Documentation
¶
Overview ¶
Package buffers provides a collection of types, constants and functions for manipulating data buffers, inspired by WeiDU's set of functions.
Index ¶
- Variables
- type Buffer
- func (b *Buffer) BufferLength() int
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) ClearError()
- func (b *Buffer) ClearModified()
- func (b *Buffer) CompressInto(offset, size, level int, buffer []byte) []byte
- func (b *Buffer) CompressReplace(offset, size, level int) int
- func (b *Buffer) DecompressInto(offset, size int, buffer []byte) []byte
- func (b *Buffer) DecompressReplace(offset, size int) int
- func (b *Buffer) DeleteBytes(offset, size int)
- func (b *Buffer) Error() error
- func (b *Buffer) GetBuffer(offset, size int) []byte
- func (b *Buffer) GetInt(offset, bitsize int) int
- func (b *Buffer) GetInt16(offset int) int16
- func (b *Buffer) GetInt32(offset int) int32
- func (b *Buffer) GetInt8(offset int) int8
- func (b *Buffer) GetOffsetArray(sevenValues ...int) []int
- func (b *Buffer) GetOffsetArray2(offset2 int, sevenValues ...int) []int
- func (b *Buffer) GetString(offset, size int, null bool) string
- func (b *Buffer) GetStringEx(offset, size int, null bool, cmap *charmap.Charmap) string
- func (b *Buffer) GetUint(offset, bitsize int) uint
- func (b *Buffer) GetUint16(offset int) uint16
- func (b *Buffer) GetUint32(offset int) uint32
- func (b *Buffer) GetUint8(offset int) uint8
- func (b *Buffer) InsertBytes(offset, size int)
- func (b *Buffer) IsModified() bool
- func (b *Buffer) PutBuffer(offset int, buf []byte)
- func (b *Buffer) PutInt16(offset int, value int16) int16
- func (b *Buffer) PutInt32(offset int, value int32) int32
- func (b *Buffer) PutInt8(offset int, value int8) int8
- func (b *Buffer) PutString(offset, size int, value string)
- func (b *Buffer) PutStringEx(offset, size int, value string, cmap *charmap.Charmap)
- func (b *Buffer) PutUint16(offset int, value uint16) uint16
- func (b *Buffer) PutUint32(offset int, value uint32) uint32
- func (b *Buffer) PutUint8(offset int, value uint8) uint8
- func (b *Buffer) ReplaceBuffer(buf []byte)
- func (b *Buffer) Save(w io.Writer)
Constants ¶
This section is empty.
Variables ¶
var ( ARE_V10_ACTORS = []int{0x54, 4, 0x58, 2, 0, 0, 0x110} ARE_V10_REGIONS = []int{0x5c, 4, 0x5a, 2, 0, 0, 0xc4} ARE_V10_SPAWN_POINTS = []int{0x60, 4, 0x64, 4, 0, 0, 0xc8} ARE_V10_ENTRANCES = []int{0x68, 4, 0x6c, 4, 0, 0, 0x68} ARE_V10_CONTAINERS = []int{0x70, 4, 0x74, 2, 0, 0, 0xc0} ARE_V10_AMBIENTS = []int{0x84, 4, 0x82, 2, 0, 0, 0xd4} ARE_V10_DOORS = []int{0xa8, 4, 0xa4, 4, 0, 0, 0xc8} ARE_V10_ANIMATIONS = []int{0xb0, 4, 0xac, 4, 0, 0, 0x4c} ARE_V91_ACTORS = []int{0x64, 4, 0x68, 2, 0, 0, 0x110} CRE_V10_KNOWN_SPELLS = []int{0x2a0, 4, 0x2a4, 4, 0, 0, 0xc} CRE_V10_SPELL_MEM_INFO = []int{0x2a8, 4, 0x2ac, 4, 0, 0, 0x10} CRE_V10_EFFECTS = []int{0x2c4, 4, 0x2c8, 4, 0, 0, 0x108} CRE_V10_ITEMS = []int{0x2bc, 4, 0x2c0, 4, 0, 0, 0x14} ITM_V10_HEADERS = []int{0x64, 4, 0x68, 2, 0, 0, 0x38} ITM_V10_GEN_EFFECTS = []int{0x6a, 4, 0x70, 2, 0x6e, 2, 0x30} SPL_V10_HEADERS = []int{0x64, 4, 0x68, 2, 0, 0, 0x28} SPL_V10_GEN_EFFECTS = []int{0x6a, 4, 0x70, 2, 0x6e, 2, 0x30} STO_V10_ITEMS_PURCHASED = []int{0x2c, 4, 0x30, 4, 0, 0, 0x4} STO_V10_ITEMS_SOLD = []int{0x34, 4, 0x38, 4, 0, 0, 0x1c} STO_V10_DRINKS = []int{0x4c, 4, 0x50, 4, 0, 0, 0x14} STO_V10_CURES = []int{0x70, 4, 0x74, 4, 0, 0, 0xc} WMP_AREAS = []int{0x34, 4, 0x30, 4, 0, 0, 0xf0} WMP_LINKS = []int{0x38, 4, 0x3c, 4, 0, 0, 0xd8} )
Predefined argument lists for function GetOffsetArray()
var ( ARE_V10_ITEMS = []int{0x78, 4, 0x44, 4, 0x40, 4, 0x14} ARE_V10_REGION_VERTICES = []int{0x7c, 4, 0x2a, 2, 0x2c, 4, 0x4} ARE_V10_CONTAINER_VERTICES = []int{0x7c, 4, 0x54, 2, 0x50, 4, 0x4} ARE_V10_DOOR_OPEN_OUTLINE_VERTICES = []int{0x7c, 4, 0x30, 2, 0x2c, 4, 0x4} ARE_V10_DOOR_CLOSED_OUTLINE_VERTICES = []int{0x7c, 4, 0x32, 2, 0x34, 4, 0x4} ARE_V10_DOOR_OPEN_CELL_VERTICES = []int{0x7c, 4, 0x4c, 2, 0x48, 4, 0x4} ARE_V10_DOOR_CLOSED_CELL_VERTICES = []int{0x7c, 4, 0x4e, 2, 0x50, 4, 0x4} CRE_V10_SPELL_MEM = []int{0x2b0, 4, 0xc, 4, 0x8, 4, 0xc} ITM_V10_HEAD_EFFECTS = []int{0x6a, 4, 0x1e, 2, 0x20, 2, 0x30} SPL_V10_HEAD_EFFECTS = []int{0x6a, 4, 0x1e, 2, 0x20, 2, 0x30} WMP_NORTH_LINKS = []int{0x38, 4, 0x54, 4, 0x50, 4, 0xd8} WMP_WEST_LINKS = []int{0x38, 4, 0x5c, 4, 0x58, 4, 0xd8} WMP_SOUTH_LINKS = []int{0x38, 4, 0x64, 4, 0x60, 4, 0xd8} WMP_EAST_LINKS = []int{0x38, 4, 0x6c, 4, 0x68, 4, 0xd8} )
Predefined argument lists for function GetOffsetArray2(). The first argument must be specified manually.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer contains the necessary information to provide read and write operations on buffer content.
func Load ¶
Load uses the given Reader to load data from the underlying buffer. The function returns a pointer to the Buffer object. Use function Error() to check if the function returned successfully.
func Wrap ¶
Wrap attempts to wrap the given byte array into a Buffer object without the need of additional copy operations.
As the Buffer takes ownership over the byte array, it is not advisable to make manual changes to the array afterwards. Wrap(nil) is functionally identical with Create().
func (*Buffer) BufferLength ¶
BufferLength returns the current length of the buffer in bytes.
func (*Buffer) Bytes ¶
Bytes returns the underlying buffer content. Returns an empty buffer if the Buffer object is in an invalid state (see Error() function).
func (*Buffer) ClearError ¶
func (b *Buffer) ClearError()
ClearError clears the error state from the last Buffer operation. Must be called for subsequent operations to work correctly.
func (*Buffer) ClearModified ¶
func (b *Buffer) ClearModified()
ClearModified explicitly marks the Buffer object as unmodified.
func (*Buffer) CompressInto ¶
CompressInto attempts to zlib compress the buffer region specified by offset and size using compression rate "level" (in range 0 - 9).
Special compression levels -2 (deflate only) and -1 (default compression) are also accepted. The compressed data is stored in the specified buffer. Returns the target buffer to accomodate to size changes. Operation is skipped if error state is set.
func (*Buffer) CompressReplace ¶
CompressReplace attempts to zlib compress the buffer region specified by offset and size using compression rate "level" which can be anything between 0 and 9.
Special compression levels -2 (deflate only) and -1 (default compression) are also accepted. Buffer size will be adjusted if needed. Returns size of the compressed block. Operation is skipped if error state is set.
func (*Buffer) DecompressInto ¶
DecompressInto attempts to decompress a zlib compressed block of the buffer and stores it in the specified buffer.
Returns the target buffer to accomodate to size changes. Operation is skipped if error state is set.
func (*Buffer) DecompressReplace ¶
DecompressReplace attempts to decompress a zlib compressed block of the buffer and replaces it with the decompressed content.
Buffer size will be adjusted if needed. Returns size of the decompressed block. Operation is skipped if error state is set.
func (*Buffer) DeleteBytes ¶
DeleteBytes removes the given amount of bytes from the buffer, starting at the specified offset. Operation is skipped if error state is set.
func (*Buffer) Error ¶
Error returns the error state of the most recent operation on Buffer. Use ClearError() function to clear the current error state.
func (*Buffer) GetBuffer ¶
GetBuffer returns a copy of the specified content region. Operation is skipped if error state is set.
func (*Buffer) GetInt ¶
GetInt returns the value at the specified offset in native int type.
bitsize specifies the size of the value to read in bits and supports 8, 16 and 32 to return a signed byte, short and long value respectively. Operation is skipped if error state is set.
func (*Buffer) GetInt16 ¶
GetInt16 returns the signed short value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) GetInt32 ¶
GetInt32 returns the signed long value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) GetInt8 ¶
GetInt8 returns the signed byte value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) GetOffsetArray ¶
GetOffsetArray is a specialized method for retrieving offsets to all available substructures of a type specified by the arguments.
It is useful to quickly determine offsets to all available ability or effect structures in an item or spell resource. Seven parameters are required. The order of parameters is as follows:
ofs, ofsSize The start offset and length of offset field to the list of substructures. count, countSize The number of substructures and length of the count field. index, indexSize An optional start index and length of index field for the substructures. Set to 0 to ignore. structSize The size of a substructure in bytes. Must be non-zero.
Returns an array of offsets for each individual substructure found in the current buffer content. The package provides a number of predefined configurations for compatible structures. Operation is skipped if error state is set.
func (*Buffer) GetOffsetArray2 ¶
GetOffsetArray2 is a specialized method for retrieving offsets to all available substructures of a type specified by the arguments.
It is most commonly used in conjunction with GetOffsetArray() to retrieve an extra parameter required for the function to work. Eight parameters are required. The order of parameters is as followed:
offset2 This is an offset to a specific substructure. It can be received by the GetOffsetArray() function. ofs, ofsSize The start offset and length of offset field to the list of substructures. Same as for GetOffsetArray(). count, countSize The number of substructures and length of the count field. Same as for GetOffsetArray(), except that it's relative to ofs2. index, indexSize An optional start index and length of index field for the substructures. Set to 0 to ignore. Same as for GetOffsetArray(), except that it's relative to ofs2. structSize The size of a substructure in bytes. Must be non-zero. Same as for GetOffsetArray().
Returns an array of offsets for each individual substructure found in the current buffer content. The package provides a number of predefined configurations for compatible structures. Operation is skipped if error state is set.
func (*Buffer) GetString ¶
GetString returns a string of given size (in bytes) from the specified offset.
If "null" is true, then string stops at the first null-character. Text encoding is assumed to be ANSI Windows-1252. Operation is skipped if error state is set.
func (*Buffer) GetStringEx ¶ added in v1.0.1
GetStringEx returns a string of given size (in bytes) from the specified offset.
If "null" is true, then string stops at the first null-character. Text encoding is specified by cmap. Specify a nil charmap to skip the ANSI decoding operation and read raw utf-8 data. Operation is skipped if error state is set.
func (*Buffer) GetUint ¶
GetUint returns the value at the specified offset in native uint type.
bitsize specifies the size of the value to read in bits and supports 8, 16 and 32 to return an unsigned byte, short and long value respectively. Operation is skipped if error state is set.
func (*Buffer) GetUint16 ¶
GetUint16 returns the unsigned short value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) GetUint32 ¶
GetUint32 returns the unsigned long value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) GetUint8 ¶
GetUint8 returns the unsigned byte value at the specified offset. Operation is skipped if error state is set.
func (*Buffer) InsertBytes ¶
InsertBytes inserts the given amount of bytes at the specified offset.
Inserted bytes are zero by default. Operation is skipped if error state is set.
func (*Buffer) IsModified ¶
IsModified returns whether the current buffer content has been modified by a previous operation.
The return value is only provided for informal purposes. None of the Buffer functions rely on it.
func (*Buffer) PutBuffer ¶
PutBuffer writes the given byte slice at the specified offset. Operation is skipped if error state is set.
func (*Buffer) PutInt16 ¶
PutInt16 writes the given signed short value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) PutInt32 ¶
PutInt32 writes the given signed long value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) PutInt8 ¶
PutInt8 writes the given signed byte value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) PutString ¶
PutString writes the given string at the specified offset.
Only the specified number of charaters will be written. Remaining space in the buffer will be filled with 0. Text encoding of is assumed to be ANSI Windows-1252. Operation is skipped if error state is set.
func (*Buffer) PutStringEx ¶ added in v1.0.1
PutStringEx writes the given string at the specified offset.
Only the specified number of charaters will be written. Remaining space in the buffer will be filled with 0. Text encoding is specified by cmap. Specify a nil charmap to skip the ANSI encoding operation and write raw utf-8 data data. Operation is skipped if error state is set.
func (*Buffer) PutUint16 ¶
PutUInt16 writes the given unsigned short value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) PutUint32 ¶
PutInt32 writes the given unsigned long value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) PutUint8 ¶
PutUInt8 writes the given unsigned byte value at the specified offset and returns the previous value. Operation is skipped if error state is set.
func (*Buffer) ReplaceBuffer ¶
ReplaceBuffer replaces the current byte array with the given array.
The operation automatically resets any invalid state (see Error() function) and marks the Buffer object as modified. Specifying a nil array assigns an empty byte array.