eq2go/internal/cps/types.go

70 lines
1.5 KiB
Go

package cps
// EQ2Type represents supported data types in EQ2 protocol
type EQ2Type int
const (
TypeInt8 EQ2Type = iota
TypeInt16
TypeInt32
TypeInt64
TypeFloat32
TypeString8
TypeString16
TypeString32
TypeColor
)
var typeMap = map[string]EQ2Type{
"int8": TypeInt8,
"int16": TypeInt16,
"int32": TypeInt32,
"int64": TypeInt64,
"float": TypeFloat32,
"string8": TypeString8,
"string16": TypeString16,
"string32": TypeString32,
"color": TypeColor,
}
// FieldDef represents a field definition with position and type info
type FieldDef struct {
Name string
Type EQ2Type
Size int // Array size, 0 for scalar, -1 for dynamic
Position int // Explicit position, -1 for append
After string
Before string
Remove bool // true if field should be removed in this version
}
// VersionDef holds field definitions for a specific version
type VersionDef struct {
Version int
Fields map[string]*FieldDef
FieldOrder []string // Preserve parsing order
}
// PacketDef represents a complete packet with all versions
type PacketDef struct {
Name string
Versions map[int]*VersionDef
}
// CompiledField represents a field in the final compiled structure
type CompiledField struct {
Name string
Type EQ2Type
Size int
Offset int // Byte offset for fixed-size packets
Dynamic bool
}
// CompiledStruct represents a compiled packet structure for a specific version
type CompiledStruct struct {
Name string
Version int
Fields []*CompiledField
Size int // Total size if fixed, -1 if dynamic
}