goearth

package module
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 21 Imported by: 0

README

goearth

Go extension API for the Habbo packet interceptor G-Earth.

Requirements

Requires Go 1.22+.

Usage

Check out the examples for reference.

Getting started
goearth CLI

The goearth CLI can be used to quickly create new extensions.

  1. Install the goearth CLI.
go install github.com/scottstamp/goearth/cmd/goearth@latest

Once it is installed, you can view the command usage with goearth new -h.

  1. Create a new extension.
goearth new -title "New extension" -desc "A new goearth extension" -author "You"
  1. Move into the newly created extension directory: cd "New extension"
  2. Run the extension with go run . - you should see the extension appear in G-Earth's extension list.

You may specify a target client with the -c flag, currently either flash (default) or shockwave.

Manual
  1. Create a new directory and save the following code as main.go.
package main

import g "github.com/scottstamp/goearth"

var ext = g.NewExt(g.ExtInfo{
    Title: "Your extension",
    Description: "Go Earth!",
    Version: "1.0",
    Author: "You",
})

func main() {
    // register event handlers and interceptors here
    ext.Run()
}
  1. Initialize a new module and install dependencies:
go mod init your-extension
go mod tidy
  1. Run the extension:
go run .

Import the in/out packages to access the respective incoming/outgoing message identifiers.

import "github.com/scottstamp/goearth/in"
import "github.com/scottstamp/goearth/out"

For the Shockwave messages, use the github.com/scottstamp/goearth/shockwave/in and out packages.

Events
On extension initialized
ext.Initialized(func(e g.InitArgs) {
    log.Printf("Extension initialized (connected=%t)", e.Connected)
})
On game connected
ext.Connected(func(e g.ConnectArgs) {
    log.Printf("Game connected (%s:%d)", e.Host, e.Port)
    log.Printf("Client %s (%s)", e.Client.Identifier, e.Client.Version)
})
On extension activated

This is when the extension's green "play" button is clicked in G-Earth.

ext.Activated(func() {
    log.Println("Extension clicked in G-Earth")
})
On game disconnected
ext.Disconnected(func() {
    log.Println("Game disconnected")    
})
Intercepting packets
All packets
ext.InterceptAll(func (e *g.Intercept) {
    log.Printf("Intercepted %s message %q\n", e.Dir(), e.Name())
})
By name
ext.Intercept(in.Chat, in.Shout, in.Whisper).With(func (e *g.Intercept) {
    idx := e.Packet.ReadInt()
    msg := e.Packet.ReadString()
    log.Printf("Entity #%d said %q", idx, msg)
})
Blocking packets
ext.Intercept(out.MoveAvatar).With(func (e *g.Intercept) {
    // prevent movement
    e.Block()
})
Modifying packets
ext.Intercept(in.Chat, in.Shout).With(func(e *g.Intercept) {
    // make everyone's chat messages uppercase
    e.Packet.ModifyStringAt(4, strings.ToUpper)
})
Reading packets
By type
x := pkt.ReadInt()
y := pkt.ReadInt()
z := pkt.ReadString()
By pointer
var x, y int
var z string
pkt.Read(&x, &y, &z)
Into a struct
type Tile struct {
    X, Y int
    Z    float32
}
tile := Tile{}
pkt.Read(&tile)
Using a custom parser by implementing Parsable
type Tile struct {
    X, Y int
    Z    float32 
}

func (v *Tile) Parse(p *g.Packet, pos *int) {
    // perform custom parsing logic here
    // make sure to use the Read*Ptr variants here
    // to ensure the provided position is advanced properly
    x := p.ReadIntPtr(pos)
    y := p.ReadIntPtr(pos)
    zStr := p.ReadStringPtr(pos)
    z, err := strconv.ParseFloat(zStr, 32)
    if err != nil {
        panic(err)
    }
    *v = Tile{ X: x, Y: y, Z: float32(z) }
}
tile := Tile{}
// Tile.Parse(...) will be invoked
pkt.Read(&tile)
Writing packets
By type
pkt.WriteInt(1)
pkt.WriteInt(2)
pkt.WriteString("3.0")
By values
// writes int, int, string
pkt.Write(1, 2, "3.0")
By struct
type Tile struct {
    X, Y int
    Z    float32
}
tile := Tile{X: 1, Y: 2, Z: 3.0}
pkt.Write(tile)
Using a custom composer by implementing Composable
type Tile struct {
    X, Y int
    Z    float32 
}

func (v Tile) Compose(p *g.Packet, pos *int) {
    // perform custom composing logic here
    // make sure to use the Write*Ptr variants here
    // to ensure the provided position is advanced properly
    p.WriteIntPtr(pos, v.X)
    p.WriteIntPtr(pos, v.Y)
    p.WriteStringPtr(pos, strconv.FormatFloat(v.Z, 'f', -1, 32))
}
Sending packets
By values
// to server
ext.Send(out.Chat, "hello, world", 0, -1)
// to client
ext.Send(in.Chat, 0, "hello, world", 0, 34, 0, 0)
// take care when sending packets to the client
// as badly formed packets will crash the game client
By packet
pkt := ext.NewPacket(in.Chat)
pkt.WriteInt(0)
pkt.WriteString("hello, world")
pkt.WriteInt(0)
pkt.WriteInt(34)
pkt.WriteInt(0)
pkt.WriteInt(0)
ext.SendPacket(pkt)
Receiving packets
log.Println("Retrieving user info...")
ext.Send(out.InfoRetrieve)
if pkt := ext.Recv(in.UserObject).Wait(); pkt != nil {
    id, name := pkt.ReadInt(), pkt.ReadString()
    log.Printf("Got user info (id: %d, name: %q)", id, name)
} else {
    log.Println("Timed out")
}

Note: do not perform any long running operations inside an intercept handler.
If you attempt to Wait for a packet inside an intercept handler,
you will never receive it as the packet's processing loop will be paused until it times out.
Launch a goroutine with the go keyword if you need to do this inside an intercept handler, for example:

ext.Intercept(in.Chat).With(func(e *g.Intercept) {
    // also, do not pass Packets to another goroutine as its buffer may no longer be valid.
    // read any values within the intercept handler and then pass those.
    msg := e.Packet.ReadStringAt(4)
    go func() {
        // perform long running operation here...
        time.Sleep(10 * time.Second)
        ext.Send(out.Shout, msg)
    }()
})
Game State Management

Game state managers are currently provided for shockwave in the github.com/scottstamp/goearth/shockwave/profile, room, inventory, and trade packages. These track the state of the game and allow you to subscribe to events, for example, here is a basic chatlog extension:

package main

import (
    "fmt"

    g "github.com/scottstamp/goearth"
    "github.com/scottstamp/goearth/shockwave/room"
)

var (
    ext = g.NewExt(g.ExtInfo{Title: "Chat log example"})
    roomMgr = room.NewManager(ext)
)

func main() {
    roomMgr.EntityChat(onEntityChat)
    ext.Run()
}

func onEntityChat(e room.EntityChatArgs) {
    fmt.Printf("%s: %s\n", e.Entity.Name, e.Message)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type B64

type B64 int16

Represents a base-64 encoded integer, used in the Shockwave client.

func (B64) Compose

func (b64 B64) Compose(p *Packet, pos *int)

func (*B64) Parse

func (b64 *B64) Parse(p *Packet, pos *int)

type Client

type Client struct {
	Version    string
	Identifier string
	Type       ClientType
}

Defines information about a game client.

type ClientType

type ClientType string

Defines a type of game client.

const (
	// Represents the Flash client.
	Flash ClientType = "FLASH"
	// Represents the Unity client.
	Unity ClientType = "UNITY"
	// Represents the Shockwave client.
	Shockwave ClientType = "SHOCKWAVE"
)

func (*ClientType) Parse

func (t *ClientType) Parse(p *Packet, pos *int)

func (ClientType) String

func (t ClientType) String() string

type Composable

type Composable interface {
	Compose(pkt *Packet, pos *int)
}

Composable represents an object that can be written to a Packet.

type ConnectArgs

type ConnectArgs struct {
	Host     string
	Port     int
	Client   Client
	Messages []MsgInfo
	Context  context.Context
}

type ConnectEvent

type ConnectEvent = Event[ConnectArgs]

type ConnectHandler

type ConnectHandler = EventHandler[ConnectArgs]

type Direction

type Direction int

Defines a message direction.

const (
	Unknown Direction = 0
	// Represents the incoming (to client) direction.
	In Direction = 1 << (iota - 1)
	// Represents the outgoing (to server) direction.
	Out
)

func (Direction) Id

func (d Direction) Id(name string) Identifier

Id creates an identifier using the provided direction and name.

func (Direction) ShortString

func (d Direction) ShortString() string

func (Direction) String

func (d Direction) String() string

type Event

type Event[T any] struct {
	// contains filtered or unexported fields
}

func (*Event[T]) Clear

func (e *Event[T]) Clear()

func (*Event[T]) Dispatch

func (e *Event[T]) Dispatch(args T)

func (*Event[T]) Register

func (e *Event[T]) Register(handlers ...EventHandler[T])

type EventHandler

type EventHandler[T any] func(e T)

type Ext

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

Provides an API to create an extension for G-Earth.

func NewExt

func NewExt(info ExtInfo) *Ext

Creates a new extension with the provided extension info.

func NewExtWithConn

func NewExtWithConn(conn net.Conn, info ExtInfo) *Ext

Creates a new extension with the provided extension info, using the specified connection.

func (*Ext) Activated

func (ext *Ext) Activated(handler VoidHandler)

Registers an event handler that is invoked when the extension is activated by the user.

func (*Ext) Client

func (ext *Ext) Client() Client

Gets the client info for the current connection.

func (*Ext) Connect

func (ext *Ext) Connect(port int) error

func (*Ext) Connected

func (ext *Ext) Connected(handler ConnectHandler)

Registers an event handler that is invoked when a game connection is established.

func (*Ext) Context

func (e *Ext) Context() context.Context

func (*Ext) Disconnected

func (ext *Ext) Disconnected(handler VoidHandler)

Registers an event handler that is invoked when the game connection is lost.

func (*Ext) ExtPort

func (e *Ext) ExtPort() int

Gets the extension port used to connect to G-Earth. Returns -1 if there is no connection.

func (*Ext) Headers

func (ext *Ext) Headers() *Headers

Gets the headers used by this extension.

func (*Ext) Initialized

func (ext *Ext) Initialized(handler InitHandler)

Registers an event handler that is invoked when the extension is initialized by G-Earth.

func (*Ext) Intercept

func (ext *Ext) Intercept(identifiers ...Identifier) InterceptBuilder

Configures a new intercept builder with the specified identifiers.

func (*Ext) InterceptAll

func (ext *Ext) InterceptAll(handler InterceptHandler)

Registers an event handler that is invoked when a packet is intercepted.

func (*Ext) IsConnected

func (e *Ext) IsConnected() bool

Gets if there is an active connection to the game.

func (*Ext) Log

func (ext *Ext) Log(a ...any)

func (*Ext) Logf

func (ext *Ext) Logf(format string, a ...any)

func (*Ext) MustConnect

func (ext *Ext) MustConnect(port int)

func (*Ext) NewPacket

func (ext *Ext) NewPacket(identifier Identifier, values ...any) *Packet

Creates a new packet with the specified message identifier and writes the specified values.

func (*Ext) Recv

func (e *Ext) Recv(identifiers ...Identifier) InlineInterceptor

Configures a new inline interceptor targeting the specified message identifiers.

func (*Ext) Register

func (ext *Ext) Register(group *InterceptGroup) InterceptRef

func (*Ext) RemoteHost

func (e *Ext) RemoteHost() string

Gets the remote host of the game server.

func (*Ext) RemotePort

func (e *Ext) RemotePort() int

Gets the remote port of the game server.

func (*Ext) Run

func (ext *Ext) Run()

Runs the extension processing loop. If the extension does not have a connection, one will be initiated using the port, cookie and filename command-line arguments via the flag package. If you do not want this behaviour, you must first call Connect before Run. This method will panic if any errors other than io.EOF occur.

func (*Ext) RunE

func (ext *Ext) RunE() (err error)

Runs the extension processing loop. If the extension does not have a connection, one will be initiated using the port, cookie and filename command-line arguments via the flag package. If you do not want this behaviour, you must first call Connect before Run.

func (*Ext) Send

func (ext *Ext) Send(identifier Identifier, values ...any)

Sends a packet with the specified message identifier and values to the server or client, based on the identifier direction.

func (*Ext) SendPacket

func (ext *Ext) SendPacket(packet *Packet)

Sends the specified packet to the server or client, based on the header direction.

type ExtArgs

type ExtArgs struct {
	Port     int
	Cookie   string
	Filename string
}

func InitFlags

func InitFlags() *ExtArgs

Registers the port, cookie, and filename command-line arguments with the flag package.

type ExtInfo

type ExtInfo struct {
	Title                string
	Author               string
	Version              string
	Description          string
	ShowEventButton      bool
	IsInstalledExtension bool
	Filename             string
	Cookie               string
	ShowLeaveButton      bool
	ShowDeleteButton     bool
}

Defines information about an extension.

type Header struct {
	Dir   Direction
	Value uint16
}

Header defines a message direction and value.

type Headers

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

Defines a map of incoming and outgoing headers.

func NewHeaders

func NewHeaders() *Headers

Creates a new header map.

func (*Headers) Add

func (h *Headers) Add(name string, header Header)

Adds a header to the map.

func (*Headers) Get

func (h *Headers) Get(id Identifier) (header Header)

Gets the header with the specified identifier. Panics if it does not exist.

func (*Headers) Is

func (h *Headers) Is(header Header, id Identifier) bool

Is returns whether the specified header matches the identifier.

func (*Headers) Name

func (h *Headers) Name(header Header) string

Name gets the name of the header. Returns an empty string if it does not exist.

func (*Headers) Reset

func (h *Headers) Reset()

Resets the header map.

func (*Headers) TryGet

func (h *Headers) TryGet(id Identifier) (header Header, ok bool)

Gets the header with the specified identifier. Panics if it does not exist.

type Id

type Id int64

Represents a unique numeric identifier.

Encoded as an int on Flash and Shockwave sessions, and a long on Unity sessions.

func (Id) Compose

func (id Id) Compose(p *Packet, pos *int)

func (*Id) Parse

func (id *Id) Parse(p *Packet, pos *int)

type Identifier

type Identifier struct {
	Dir  Direction
	Name string
}

Identifier defines a message direction and name.

func (Identifier) String

func (id Identifier) String() string

type InitArgs

type InitArgs struct {
	Connected bool
}

type InitEvent

type InitEvent = Event[InitArgs]

type InitHandler

type InitHandler = EventHandler[InitArgs]

type InlineInterceptor

type InlineInterceptor interface {
	// Configures the intercept condition.
	If(condition func(p *Packet) bool) InlineInterceptor
	// Configures the interceptor to block the intercepted packet.
	Block() InlineInterceptor
	// Configures the timeout duration of the interceptor.
	Timeout(duration time.Duration) InlineInterceptor
	// Configures the timeout duration of the interceptor.
	TimeoutMs(ms time.Duration) InlineInterceptor
	// Configures the timeout duration of the interceptor.
	TimeoutSec(sec time.Duration) InlineInterceptor
	// Returns a channel that will signal the intercepted packet.
	// Returns nil if the interceptor times out or is canceled.
	Await() <-chan *Packet
	// Waits for the packet to be intercepted and then returns it.
	// Returns nil if the interceptor times out or is canceled.
	Wait() *Packet
	// Cancels the interceptor.
	Cancel()
}

func NewInlineInterceptor

func NewInlineInterceptor(interceptor Interceptor, identifiers []Identifier) InlineInterceptor

type Intercept

type Intercept struct {
	Packet *Packet // The intercepted packet.
	// contains filtered or unexported fields
}

Intercept holds the event arguments for an intercepted packet.

func NewIntercept

func NewIntercept(interceptor Interceptor, packet *Packet, sequence int, blocked bool) *Intercept

func (*Intercept) Block

func (args *Intercept) Block()

Blocks the intercepted packet.

func (*Intercept) Deregister

func (args *Intercept) Deregister()

Deregisters the current intercept handler.

func (*Intercept) Dir

func (args *Intercept) Dir() Direction

Gets the direction of the intercepted message.

func (*Intercept) Interceptor

func (args *Intercept) Interceptor() Interceptor

Gets the interceptor that intercepted this message.

func (*Intercept) Is

func (args *Intercept) Is(id Identifier) bool

Is returns whether the intercepted packet header matches the specified identifier.

func (*Intercept) IsBlocked

func (args *Intercept) IsBlocked() bool

IsBlocked gets whether the packet has been flagged to be blocked by the interceptor.

func (*Intercept) Name

func (args *Intercept) Name() string

Name gets the name of the intercepted packet header.

func (*Intercept) Sequence

func (args *Intercept) Sequence() int

Gets the incremental packet sequence number.

type InterceptArgs deprecated

type InterceptArgs = Intercept

Deprecated: Use Intercept.

type InterceptBuilder

type InterceptBuilder interface {
	// Flags the intercept as transient.
	Transient() InterceptBuilder
	// Registers the intercept handler and returns a reference.
	With(handler InterceptHandler) InterceptRef
}

func NewInterceptBuilder

func NewInterceptBuilder(interceptor Interceptor, ids ...Identifier) InterceptBuilder

type InterceptEvent

type InterceptEvent = Event[*Intercept]

type InterceptGroup

type InterceptGroup struct {
	Identifiers map[Identifier]struct{}
	Handler     InterceptHandler
	Transient   bool
}

type InterceptHandler

type InterceptHandler = EventHandler[*Intercept]

type InterceptRef

type InterceptRef interface {
	// Deregisters the intercept handler.
	Deregister()
}

Represents a reference to an intercept handler.

type Interceptor

type Interceptor interface {
	Context() context.Context
	Client() Client
	Headers() *Headers
	Send(id Identifier, values ...any)
	SendPacket(*Packet)
	Recv(identifiers ...Identifier) InlineInterceptor
	Register(*InterceptGroup) InterceptRef
	Intercept(...Identifier) InterceptBuilder

	Initialized(EventHandler[InitArgs])
	Connected(EventHandler[ConnectArgs])
	Disconnected(VoidHandler)
}

type Length

type Length int32

Repesents the length of an array or collection of items.

Encoded as a short on Shockwave and Unity, otherwise as an int.

func (Length) Compose

func (length Length) Compose(p *Packet, pos *int)

func (*Length) Parse

func (length *Length) Parse(p *Packet, pos *int)

type MsgInfo

type MsgInfo struct {
	Id        int
	Hash      string
	Name      string
	Structure string
	Outgoing  bool
	Source    string
}

Defines information about a message.

type Packet

type Packet struct {
	Client ClientType
	Header Header
	Data   []byte
	Pos    int
}

func (*Packet) Copy

func (p *Packet) Copy() *Packet

Makes a copy of the packet.

func (*Packet) Length

func (p *Packet) Length() int

Gets the length of the packet's data.

func (*Packet) ModifyString

func (p *Packet) ModifyString(transform func(string) string) *Packet

Modifies a string at the current position.

func (*Packet) ModifyStringAt

func (p *Packet) ModifyStringAt(pos int, transform func(string) string) *Packet

Modifies a string at the specified position.

func (*Packet) ModifyStringPtr

func (p *Packet) ModifyStringPtr(pos *int, transform func(string) string) *Packet

Modifies a string at the specified position and advances it.

func (*Packet) Read

func (p *Packet) Read(vars ...any)

Reads into the specified variables from the current position. The provided variables must be a pointer type or implement Parsable.

func (*Packet) ReadAt

func (p *Packet) ReadAt(pos int, vars ...any)

Reads into the specified variables at the specified position. The provided variables must be a pointer type or implement Parsable.

func (*Packet) ReadBool

func (p *Packet) ReadBool() bool

Reads a bool from the current position.

Read as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) ReadBoolAt

func (p *Packet) ReadBoolAt(pos int) bool

Reads a bool at the specified position.

Read as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) ReadBoolPtr

func (p *Packet) ReadBoolPtr(pos *int) (value bool)

Reads a bool from the specified position.

Read as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) ReadBuffer

func (p *Packet) ReadBuffer(buf []byte)

Reads into the specified byte slice from the current position.

func (*Packet) ReadBufferAt

func (p *Packet) ReadBufferAt(pos int, buf []byte)

Reads into the specified byte slice from the specified position.

func (*Packet) ReadBufferPtr

func (p *Packet) ReadBufferPtr(pos *int, buf []byte)

Reads into the specified byte slice from the specified position and advances it.

func (*Packet) ReadByte

func (p *Packet) ReadByte() byte

Reads a byte from the current position.

func (*Packet) ReadByteAt

func (p *Packet) ReadByteAt(pos int) byte

Reads a byte from the specified position.

func (*Packet) ReadBytePtr

func (p *Packet) ReadBytePtr(pos *int) (value byte)

Reads a byte from the specified position and advances it.

func (*Packet) ReadBytes

func (p *Packet) ReadBytes(length int) []byte

Copies `n` bytes from the current position.

func (*Packet) ReadBytesAt

func (p *Packet) ReadBytesAt(pos int, length int) []byte

Copies `n` bytes from the specified position.

func (*Packet) ReadBytesPtr

func (p *Packet) ReadBytesPtr(pos *int, n int) (value []byte)

Copies `n` bytes from the specified position and advances it.

func (*Packet) ReadFloat

func (p *Packet) ReadFloat() float32

Reads a float from the current position.

Read as a string and parsed to a float on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) ReadFloatAt

func (p *Packet) ReadFloatAt(pos int) float32

Reads a float at the specified position.

Read as a string and parsed to a float on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) ReadFloatPtr

func (p *Packet) ReadFloatPtr(pos *int) float32

Reads a float from the specified position.

Read as a string and parsed to a float on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) ReadInt

func (p *Packet) ReadInt() int

Reads an int from the current position.

Read as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) ReadIntAt

func (p *Packet) ReadIntAt(pos int) int

Reads an int at the specified position.

Read as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) ReadIntPtr

func (p *Packet) ReadIntPtr(pos *int) (value int)

Reads an int from the specified position.

Read as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) ReadLong

func (p *Packet) ReadLong() int64

Reads a long from the current position.

Only supported on Unity sessions.

func (*Packet) ReadLongAt

func (p *Packet) ReadLongAt(pos int) int64

Reads a long at the specified position.

Only supported on Unity sessions.

func (*Packet) ReadLongPtr

func (p *Packet) ReadLongPtr(pos *int) (value int64)

Reads a long from the specified position and advances it.

Only supported on Unity sessions.

func (*Packet) ReadPtr

func (p *Packet) ReadPtr(pos *int, vars ...any)

Reads into the specified variables from the specified position and advances it. The provided variables must be a pointer type or implement Parsable.

func (*Packet) ReadShort

func (p *Packet) ReadShort() int16

Reads a short from the current position.

Read as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) ReadShortAt

func (p *Packet) ReadShortAt(pos int) int16

Reads a short at the specified position.

Read as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) ReadShortPtr

func (p *Packet) ReadShortPtr(pos *int) (value int16)

Reads a short from the specified position and advances it.

Read as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) ReadString

func (p *Packet) ReadString() string

Reads a string from the current position.

Read as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

func (*Packet) ReadStringAt

func (p *Packet) ReadStringAt(pos int) string

Reads a string at the specified position.

Read as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

func (*Packet) ReadStringPtr

func (p *Packet) ReadStringPtr(pos *int) (value string)

Reads a string from the specified position and advances it.

Read as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

func (*Packet) ReplaceString

func (p *Packet) ReplaceString(value string) *Packet

Replaces a string at the current position.

func (*Packet) ReplaceStringAt

func (p *Packet) ReplaceStringAt(pos int, value string) *Packet

Replaces a string at the specified position.

func (*Packet) ReplaceStringPtr

func (p *Packet) ReplaceStringPtr(pos *int, value string) *Packet

Replaces a string at the specified position and advances it.

func (*Packet) Skip

func (p *Packet) Skip(values ...any)

Skips the types indicated specified by the provided values from the current position.

func (*Packet) Write

func (p *Packet) Write(values ...any) *Packet

Writes the specified values at the current position.

func (*Packet) WriteAt

func (p *Packet) WriteAt(pos int, values ...any) *Packet

Writes the specified values at the specified position.

func (*Packet) WriteBool

func (p *Packet) WriteBool(value bool) *Packet

Writes a bool at the current position.

Written as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) WriteBoolAt

func (p *Packet) WriteBoolAt(pos int, value bool) *Packet

Writes a bool at the specified position.

Written as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) WriteBoolPtr

func (p *Packet) WriteBoolPtr(pos *int, value bool) *Packet

Writes a bool at the specified position and advances it.

Written as a VL64 on Shockwave, otherwise as a byte.

func (*Packet) WriteByte

func (p *Packet) WriteByte(value byte) *Packet

Writes a byte at the current position.

func (*Packet) WriteByteAt

func (p *Packet) WriteByteAt(pos int, value byte) *Packet

Writes a byte at the specified position.

func (*Packet) WriteBytePtr

func (p *Packet) WriteBytePtr(pos *int, value byte) *Packet

Writes a byte at the specified position and advances it.

func (*Packet) WriteBytes

func (p *Packet) WriteBytes(value []byte) *Packet

Writes a slice of bytes at the current position.

func (*Packet) WriteBytesAt

func (p *Packet) WriteBytesAt(pos int, value []byte) *Packet

Writes a slice of bytes at the specified position.

func (*Packet) WriteBytesPtr

func (p *Packet) WriteBytesPtr(pos *int, value []byte) *Packet

Writes a slice of bytes at the specified position and advances it.

func (*Packet) WriteFloat

func (p *Packet) WriteFloat(value float32) *Packet

Writes a float at the current position.

Written as a string on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) WriteFloatAt

func (p *Packet) WriteFloatAt(pos int, value float32) *Packet

Writes a float at the specified position.

Written as a string on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) WriteFloatPtr

func (p *Packet) WriteFloatPtr(pos *int, value float32) *Packet

Writes a float at the specified position and advances it.

Written as a string on Flash and Shockwave sessions, otherwise as a float32.

func (*Packet) WriteInt

func (p *Packet) WriteInt(value int) *Packet

Writes an int at the current position.

Written as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) WriteIntAt

func (p *Packet) WriteIntAt(pos, value int) *Packet

Writes an int at the specified position.

Written as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) WriteIntPtr

func (p *Packet) WriteIntPtr(pos *int, value int) *Packet

Writes an int at the specified position and advances it.

Written as a VL64 on Shockwave, otherwise as an int32.

func (*Packet) WriteLong

func (p *Packet) WriteLong(value int64) *Packet

Writes a long at the current position.

Only supported on Unity sessions.

func (*Packet) WriteLongAt

func (p *Packet) WriteLongAt(pos int, value int64) *Packet

Writes a long at the specified position.

Only supported on Unity sessions.

func (*Packet) WriteLongPtr

func (p *Packet) WriteLongPtr(pos *int, value int64) *Packet

Writes a long at the specified position and advances it.

Only supported on Unity sessions.

func (*Packet) WritePtr

func (p *Packet) WritePtr(pos *int, values ...any) *Packet

Writes the specified values at the specified position and advances it.

func (*Packet) WriteShort

func (p *Packet) WriteShort(value int16) *Packet

Writes a short at the current position.

Written as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) WriteShortAt

func (p *Packet) WriteShortAt(pos int, value int16) *Packet

Writes a short at the specified position.

Written as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) WriteShortPtr

func (p *Packet) WriteShortPtr(pos *int, value int16) *Packet

Writes a short at the specified position and advances it.

Written as a VL64 on incoming Shockwave, B64 on outgoing Shockwave, otherwise as an int16.

func (*Packet) WriteString

func (p *Packet) WriteString(value string) *Packet

Writes a string at the current position.

Written as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

func (*Packet) WriteStringAt

func (p *Packet) WriteStringAt(pos int, value string) *Packet

Writes a string at the specified position.

Written as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

func (*Packet) WriteStringPtr

func (p *Packet) WriteStringPtr(pos *int, value string) *Packet

Writes a string at the specified position and advances it.

Written as a UTF-8 string terminated with an 0x02 byte on (incoming) Shockwave, otherwise as a short length-prefixed UTF-8 string.

type Parsable

type Parsable interface {
	Parse(pkt *Packet, pos *int)
}

Parsable represents an object that can be read from a Packet.

type VL64

type VL64 int32

Represents a variable-length base-64 encoded integer, used in the Shockwave client.

func (VL64) Compose

func (vl64 VL64) Compose(p *Packet, pos *int)

func (*VL64) Parse

func (vl64 *VL64) Parse(p *Packet, pos *int)

type VoidEvent

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

func (*VoidEvent) Dispatch

func (e *VoidEvent) Dispatch()

func (*VoidEvent) Register

func (e *VoidEvent) Register(handler VoidHandler)

type VoidHandler

type VoidHandler func()

Directories

Path Synopsis
cmd
goearth command
internal
shockwave
in
nav
out

Jump to

Keyboard shortcuts

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