Documentation
¶
Index ¶
- type B64
- type Client
- type ClientType
- type Composable
- type ConnectArgs
- type ConnectEvent
- type ConnectHandler
- type Direction
- type Event
- type EventHandler
- type Ext
- func (ext *Ext) Activated(handler VoidHandler)
- func (ext *Ext) Client() Client
- func (ext *Ext) Connect(port int) error
- func (ext *Ext) Connected(handler ConnectHandler)
- func (e *Ext) Context() context.Context
- func (ext *Ext) Disconnected(handler VoidHandler)
- func (e *Ext) ExtPort() int
- func (ext *Ext) Headers() *Headers
- func (ext *Ext) Initialized(handler InitHandler)
- func (ext *Ext) Intercept(identifiers ...Identifier) InterceptBuilder
- func (ext *Ext) InterceptAll(handler InterceptHandler)
- func (e *Ext) IsConnected() bool
- func (ext *Ext) Log(a ...any)
- func (ext *Ext) Logf(format string, a ...any)
- func (ext *Ext) MustConnect(port int)
- func (ext *Ext) NewPacket(identifier Identifier, values ...any) *Packet
- func (e *Ext) Recv(identifiers ...Identifier) InlineInterceptor
- func (ext *Ext) Register(group *InterceptGroup) InterceptRef
- func (e *Ext) RemoteHost() string
- func (e *Ext) RemotePort() int
- func (ext *Ext) Run()
- func (ext *Ext) RunE() (err error)
- func (ext *Ext) Send(identifier Identifier, values ...any)
- func (ext *Ext) SendPacket(packet *Packet)
- type ExtArgs
- type ExtInfo
- type Header
- type Headers
- type Id
- type Identifier
- type InitArgs
- type InitEvent
- type InitHandler
- type InlineInterceptor
- type Intercept
- func (args *Intercept) Block()
- func (args *Intercept) Deregister()
- func (args *Intercept) Dir() Direction
- func (args *Intercept) Interceptor() Interceptor
- func (args *Intercept) Is(id Identifier) bool
- func (args *Intercept) IsBlocked() bool
- func (args *Intercept) Name() string
- func (args *Intercept) Sequence() int
- type InterceptArgsdeprecated
- type InterceptBuilder
- type InterceptEvent
- type InterceptGroup
- type InterceptHandler
- type InterceptRef
- type Interceptor
- type Length
- type MsgInfo
- type Packet
- func (p *Packet) Copy() *Packet
- func (p *Packet) Length() int
- func (p *Packet) ModifyString(transform func(string) string) *Packet
- func (p *Packet) ModifyStringAt(pos int, transform func(string) string) *Packet
- func (p *Packet) ModifyStringPtr(pos *int, transform func(string) string) *Packet
- func (p *Packet) Read(vars ...any)
- func (p *Packet) ReadAt(pos int, vars ...any)
- func (p *Packet) ReadBool() bool
- func (p *Packet) ReadBoolAt(pos int) bool
- func (p *Packet) ReadBoolPtr(pos *int) (value bool)
- func (p *Packet) ReadBuffer(buf []byte)
- func (p *Packet) ReadBufferAt(pos int, buf []byte)
- func (p *Packet) ReadBufferPtr(pos *int, buf []byte)
- func (p *Packet) ReadByte() byte
- func (p *Packet) ReadByteAt(pos int) byte
- func (p *Packet) ReadBytePtr(pos *int) (value byte)
- func (p *Packet) ReadBytes(length int) []byte
- func (p *Packet) ReadBytesAt(pos int, length int) []byte
- func (p *Packet) ReadBytesPtr(pos *int, n int) (value []byte)
- func (p *Packet) ReadFloat() float32
- func (p *Packet) ReadFloatAt(pos int) float32
- func (p *Packet) ReadFloatPtr(pos *int) float32
- func (p *Packet) ReadInt() int
- func (p *Packet) ReadIntAt(pos int) int
- func (p *Packet) ReadIntPtr(pos *int) (value int)
- func (p *Packet) ReadLong() int64
- func (p *Packet) ReadLongAt(pos int) int64
- func (p *Packet) ReadLongPtr(pos *int) (value int64)
- func (p *Packet) ReadPtr(pos *int, vars ...any)
- func (p *Packet) ReadShort() int16
- func (p *Packet) ReadShortAt(pos int) int16
- func (p *Packet) ReadShortPtr(pos *int) (value int16)
- func (p *Packet) ReadString() string
- func (p *Packet) ReadStringAt(pos int) string
- func (p *Packet) ReadStringPtr(pos *int) (value string)
- func (p *Packet) ReplaceString(value string) *Packet
- func (p *Packet) ReplaceStringAt(pos int, value string) *Packet
- func (p *Packet) ReplaceStringPtr(pos *int, value string) *Packet
- func (p *Packet) Skip(values ...any)
- func (p *Packet) Write(values ...any) *Packet
- func (p *Packet) WriteAt(pos int, values ...any) *Packet
- func (p *Packet) WriteBool(value bool) *Packet
- func (p *Packet) WriteBoolAt(pos int, value bool) *Packet
- func (p *Packet) WriteBoolPtr(pos *int, value bool) *Packet
- func (p *Packet) WriteByte(value byte) *Packet
- func (p *Packet) WriteByteAt(pos int, value byte) *Packet
- func (p *Packet) WriteBytePtr(pos *int, value byte) *Packet
- func (p *Packet) WriteBytes(value []byte) *Packet
- func (p *Packet) WriteBytesAt(pos int, value []byte) *Packet
- func (p *Packet) WriteBytesPtr(pos *int, value []byte) *Packet
- func (p *Packet) WriteFloat(value float32) *Packet
- func (p *Packet) WriteFloatAt(pos int, value float32) *Packet
- func (p *Packet) WriteFloatPtr(pos *int, value float32) *Packet
- func (p *Packet) WriteInt(value int) *Packet
- func (p *Packet) WriteIntAt(pos, value int) *Packet
- func (p *Packet) WriteIntPtr(pos *int, value int) *Packet
- func (p *Packet) WriteLong(value int64) *Packet
- func (p *Packet) WriteLongAt(pos int, value int64) *Packet
- func (p *Packet) WriteLongPtr(pos *int, value int64) *Packet
- func (p *Packet) WritePtr(pos *int, values ...any) *Packet
- func (p *Packet) WriteShort(value int16) *Packet
- func (p *Packet) WriteShortAt(pos int, value int16) *Packet
- func (p *Packet) WriteShortPtr(pos *int, value int16) *Packet
- func (p *Packet) WriteString(value string) *Packet
- func (p *Packet) WriteStringAt(pos int, value string) *Packet
- func (p *Packet) WriteStringPtr(pos *int, value string) *Packet
- type Parsable
- type VL64
- type VoidEvent
- type VoidHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
Composable represents an object that can be written to a Packet.
type ConnectArgs ¶
type ConnectEvent ¶
type ConnectEvent = Event[ConnectArgs]
type ConnectHandler ¶
type ConnectHandler = EventHandler[ConnectArgs]
type Direction ¶
type Direction int
Defines a message direction.
func (Direction) Id ¶
func (d Direction) Id(name string) Identifier
Id creates an identifier using the provided direction and name.
func (Direction) ShortString ¶
type Event ¶
type Event[T any] struct { // contains filtered or unexported fields }
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 NewExtWithConn ¶
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) Connected ¶
func (ext *Ext) Connected(handler ConnectHandler)
Registers an event handler that is invoked when a game connection is established.
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 ¶
Gets the extension port used to connect to G-Earth. Returns -1 if there is no connection.
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 ¶
Gets if there is an active connection to the game.
func (*Ext) MustConnect ¶
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) 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 ¶
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 ¶
Sends the specified packet to the server or client, based on the header direction.
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 Headers ¶
type Headers struct {
// contains filtered or unexported fields
}
Defines a map of incoming and outgoing headers.
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.
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.
type Identifier ¶
Identifier defines a message direction and name.
func (Identifier) String ¶
func (id Identifier) String() string
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) Deregister ¶
func (args *Intercept) Deregister()
Deregisters the current intercept handler.
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 ¶
IsBlocked gets whether the packet has been flagged to be blocked by the interceptor.
type InterceptArgs
deprecated
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 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.
type Packet ¶
type Packet struct {
Client ClientType
Header Header
Data []byte
Pos int
}
func (*Packet) ModifyString ¶
Modifies a string at the current position.
func (*Packet) ModifyStringAt ¶
Modifies a string at the specified position.
func (*Packet) ModifyStringPtr ¶
Modifies a string at the specified position and advances it.
func (*Packet) Read ¶
Reads into the specified variables from the current position. The provided variables must be a pointer type or implement Parsable.
func (*Packet) ReadAt ¶
Reads into the specified variables at the specified position. The provided variables must be a pointer type or implement Parsable.
func (*Packet) ReadBool ¶
Reads a bool from the current position.
Read as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) ReadBoolAt ¶
Reads a bool at the specified position.
Read as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) ReadBoolPtr ¶
Reads a bool from the specified position.
Read as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) ReadBuffer ¶
Reads into the specified byte slice from the current position.
func (*Packet) ReadBufferAt ¶
Reads into the specified byte slice from the specified position.
func (*Packet) ReadBufferPtr ¶
Reads into the specified byte slice from the specified position and advances it.
func (*Packet) ReadByteAt ¶
Reads a byte from the specified position.
func (*Packet) ReadBytePtr ¶
Reads a byte from the specified position and advances it.
func (*Packet) ReadBytesAt ¶
Copies `n` bytes from the specified position.
func (*Packet) ReadBytesPtr ¶
Copies `n` bytes from the specified position and advances it.
func (*Packet) ReadFloat ¶
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 ¶
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 ¶
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 ¶
Reads an int from the current position.
Read as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) ReadIntAt ¶
Reads an int at the specified position.
Read as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) ReadIntPtr ¶
Reads an int from the specified position.
Read as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) ReadLongAt ¶
Reads a long at the specified position.
Only supported on Unity sessions.
func (*Packet) ReadLongPtr ¶
Reads a long from the specified position and advances it.
Only supported on Unity sessions.
func (*Packet) ReadPtr ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Replaces a string at the current position.
func (*Packet) ReplaceStringAt ¶
Replaces a string at the specified position.
func (*Packet) ReplaceStringPtr ¶
Replaces a string at the specified position and advances it.
func (*Packet) Skip ¶
Skips the types indicated specified by the provided values from the current position.
func (*Packet) WriteBool ¶
Writes a bool at the current position.
Written as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) WriteBoolAt ¶
Writes a bool at the specified position.
Written as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) WriteBoolPtr ¶
Writes a bool at the specified position and advances it.
Written as a VL64 on Shockwave, otherwise as a byte.
func (*Packet) WriteByteAt ¶
Writes a byte at the specified position.
func (*Packet) WriteBytePtr ¶
Writes a byte at the specified position and advances it.
func (*Packet) WriteBytes ¶
Writes a slice of bytes at the current position.
func (*Packet) WriteBytesAt ¶
Writes a slice of bytes at the specified position.
func (*Packet) WriteBytesPtr ¶
Writes a slice of bytes at the specified position and advances it.
func (*Packet) WriteFloat ¶
Writes a float at the current position.
Written as a string on Flash and Shockwave sessions, otherwise as a float32.
func (*Packet) WriteFloatAt ¶
Writes a float at the specified position.
Written as a string on Flash and Shockwave sessions, otherwise as a float32.
func (*Packet) WriteFloatPtr ¶
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 ¶
Writes an int at the current position.
Written as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) WriteIntAt ¶
Writes an int at the specified position.
Written as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) WriteIntPtr ¶
Writes an int at the specified position and advances it.
Written as a VL64 on Shockwave, otherwise as an int32.
func (*Packet) WriteLongAt ¶
Writes a long at the specified position.
Only supported on Unity sessions.
func (*Packet) WriteLongPtr ¶
Writes a long at the specified position and advances it.
Only supported on Unity sessions.
func (*Packet) WriteShort ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type VL64 ¶
type VL64 int32
Represents a variable-length base-64 encoded integer, used in the Shockwave client.
type VoidEvent ¶
type VoidEvent struct {
// contains filtered or unexported fields
}
func (*VoidEvent) Register ¶
func (e *VoidEvent) Register(handler VoidHandler)
type VoidHandler ¶
type VoidHandler func()