Types specific to EQ2's protocol.
Find a file
Sky Johnson 7068c1f434 Refactor types package: remove string wrappers, add helper methods
- Remove EQ2_8BitString, EQ2_16BitString, EQ2_32BitString wrapper types
- String serialization now handled by packetstruct package
- Add comprehensive helper methods to EQ2_Color (constructors, conversions, comparisons)
- Add equipment slot constants (25 slots) with validation helpers
- Add EQ2_Equipment full array type with slot management methods
- Add WorldTime type with validation, comparison, and arithmetic operations
- Add comprehensive test coverage for all new functionality
- Update README documentation for simplified string handling
2025-12-27 12:03:09 -06:00
color.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
color_test.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
constants.go Add types implementations, first pass 2025-12-26 13:38:16 -06:00
equipment.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
equipment_slots.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
equipment_test.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
go.mod first commit 2025-12-26 11:45:19 -06:00
helpers.go Add types implementations, first pass 2025-12-26 13:38:16 -06:00
README.md Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
types.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
worldtime.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00
worldtime_test.go Refactor types package: remove string wrappers, add helper methods 2025-12-27 12:03:09 -06:00

EQ2 Types Package

Core EverQuest 2 protocol type definitions for use across the EQ2 emulator project.

Overview

This package provides the fundamental data types and constants used by the EQ2 network protocol. It serves as a foundation library that can be imported by any component that needs to work with EQ2-specific data structures.

Types

String Types

EQ2 uses length-prefixed strings with different prefix sizes. String serialization is handled by the packetstruct package - you work directly with Go string values in your code.

The protocol supports three string formats:

  • 8-bit strings: 1-byte length prefix (max 255 bytes)
  • 16-bit strings: 2-byte length prefix (max 65,535 bytes)
  • 32-bit strings: 4-byte length prefix (max 4GB)

String type information is specified in packet struct definitions, not in the type system.

Color Types

type EQ2_Color struct {
    Red   uint8  // Red component (0-255)
    Green uint8  // Green component (0-255)
    Blue  uint8  // Blue component (0-255)
}

Equipment Types

type EQ2_EquipmentItem struct {
    Type           uint16  // Equipment type ID
    ColorRed       uint8   // Primary color - red
    ColorGreen     uint8   // Primary color - green
    ColorBlue      uint8   // Primary color - blue
    HighlightRed   uint8   // Highlight color - red
    HighlightGreen uint8   // Highlight color - green
    HighlightBlue  uint8   // Highlight color - blue
}

Constants

Data Type Constants

The package defines constants for all EQ2 packet field types:

const (
    DataStructNone            uint8 = 0
    DataStructInt8            uint8 = 1   // Unsigned 8-bit integer
    DataStructInt16           uint8 = 2   // Unsigned 16-bit integer
    DataStructInt32           uint8 = 3   // Unsigned 32-bit integer
    DataStructInt64           uint8 = 4   // Unsigned 64-bit integer
    DataStructFloat           uint8 = 5   // 32-bit float
    DataStructDouble          uint8 = 6   // 64-bit float
    DataStructColor           uint8 = 7   // RGB color (3 bytes)
    DataStructSint8           uint8 = 8   // Signed 8-bit integer
    DataStructSint16          uint8 = 9   // Signed 16-bit integer
    DataStructSint32          uint8 = 10  // Signed 32-bit integer
    DataStructChar            uint8 = 11  // Single character
    DataStructEQ2_8BitString  uint8 = 12  // 1-byte length prefix string
    DataStructEQ2_16BitString uint8 = 13  // 2-byte length prefix string
    DataStructEQ2_32BitString uint8 = 14  // 4-byte length prefix string
    DataStructEquipment       uint8 = 15  // Equipment item (8 bytes)
    DataStructArray           uint8 = 16  // Dynamic array
    DataStructItem            uint8 = 17  // Item data
    DataStructSint64          uint8 = 18  // Signed 64-bit integer
)

Helper Functions

TypeNameToConstant

Converts a type name string to its corresponding type constant. Case-insensitive.

typeConst := types.TypeNameToConstant("int32")
// Returns: DataStructInt32 (3)

typeConst = types.TypeNameToConstant("EQ2_16BitString")
// Returns: DataStructEQ2_16BitString (13)

Supported type names:

  • Integers: "int8", "int16", "int32", "int64"
  • Signed integers: "sint8", "sint16", "sint32", "sint64"
  • Floats: "float", "double"
  • Strings: "eq2_8bit_string", "eq2_16bit_string", "eq2_32bit_string"
  • Special: "char", "color", "equipment", "array", "item"

TypeConstantToName

Converts a type constant to a readable name string.

name := types.TypeConstantToName(types.DataStructInt32)
// Returns: "int32"

name = types.TypeConstantToName(types.DataStructEQ2_16BitString)
// Returns: "eq2_16bit_string"

GetTypeSize

Returns the size in bytes for fixed-size types, or -1 for variable-size types.

size := types.GetTypeSize(types.DataStructInt32)
// Returns: 4

size = types.GetTypeSize(types.DataStructColor)
// Returns: 3

size = types.GetTypeSize(types.DataStructEQ2_8BitString)
// Returns: -1 (variable size)

Usage Example

import "git.sharkk.net/eq2go/types"

// Create a color
color := types.EQ2_Color{
    Red:   255,
    Green: 128,
    Blue:  0,
}

// Create equipment
equipment := types.EQ2_EquipmentItem{
    Type:         1234,
    ColorRed:     255,
    ColorGreen:   128,
    ColorBlue:    0,
    HighlightRed: 200,
    HighlightGreen: 200,
    HighlightBlue: 200,
}

// Use type constants
if fieldType == types.DataStructInt32 {
    // Handle int32 field
}

// Convert type names
typeName := "equipment"
typeConst := types.TypeNameToConstant(typeName)

// Strings are used directly (no wrapper types)
packet.SetDataByName("username", "PlayerName")
username, _ := packet.GetStringByName("username")

Compatibility

This package matches the C++ implementation's type system and is verified to produce byte-for-byte compatible output.

License

Part of the EQ2 Emulator project.