osrscache

package module
v0.0.0-...-f83daf0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 14 Imported by: 0

README

osrscache

A Go library for reading the Old School Runescape cache.

Note: This library is still under development.

Usage

package main

import (
	"log"
	"time"

	"github.com/joeychilson/osrscache"
	"github.com/joeychilson/osrscache/openrs2"
)

func main() {
	startTime := time.Now()

	store, err := openrs2.Open("./cache")
	if err != nil {
		log.Fatalf("opening store: %v", err)
	}

	cache := osrscache.New(store)

	items, err := cache.Items()
	if err != nil {
		log.Fatalf("getting items: %v", err)
	}
	log.Printf("loaded %d items", len(items))

	npcs, err := cache.NPCs()
	if err != nil {
		log.Fatalf("getting npcs: %v", err)
	}
	log.Printf("loaded %d npcs", len(npcs))

	objs, err := cache.Objects()
	if err != nil {
		log.Fatalf("getting objects: %v", err)
	}
	log.Printf("loaded %d objects", len(objs))

	structs, err := cache.Structs()
	if err != nil {
		log.Fatalf("getting structs: %v", err)
	}
	log.Printf("loaded %d structs", len(structs))

	enums, err := cache.Enums()
	if err != nil {
		log.Fatalf("getting enums: %v", err)
	}
	log.Printf("loaded %d enums", len(enums))

	sprites, err := cache.Sprites()
	if err != nil {
		log.Fatalf("getting sprites: %v", err)
	}
	log.Printf("loaded %d sprites", len(sprites))

	textures, err := cache.Textures()
	if err != nil {
		log.Fatalf("getting textures: %v", err)
	}
	log.Printf("loaded %d textures", len(textures))

	log.Printf("took: %v", time.Since(startTime))
}

Acknowledgements

Documentation

Index

Constants

View Source
const (
	CompressionNone  = 0
	CompressionBZIP2 = 1
	CompressionGZIP  = 2
)
View Source
const (
	DigestBits  = 512
	DigestBytes = DigestBits >> 3
)
View Source
const (
	FlagNames                 = 0x01
	FlagDigests               = 0x02
	FlagLengths               = 0x04
	FlagUncompressedChecksums = 0x08
)
View Source
const (
	FlagColumnMajor = 0x1
	FlagAlpha       = 0x2
)
View Source
const (
	MaxArchive = 255
)

Variables

This section is empty.

Functions

func DecompressData

func DecompressData(data []byte) ([]byte, error)

Types

type Cache

type Cache struct {
	Store Store
}

func New

func New(store Store) *Cache

func (*Cache) Enum

func (c *Cache) Enum(id uint16) (*Enum, error)

func (*Cache) Enums

func (c *Cache) Enums() (map[uint16]*Enum, error)

func (*Cache) ExportEnums

func (c *Cache) ExportEnums(outputDir string, mode JSONExportMode) error

func (*Cache) ExportItems

func (c *Cache) ExportItems(outputDir string, mode JSONExportMode) error

func (*Cache) ExportNPCs

func (c *Cache) ExportNPCs(outputDir string, mode JSONExportMode) error

func (*Cache) ExportObjects

func (c *Cache) ExportObjects(outputDir string, mode JSONExportMode) error

func (*Cache) ExportSprites

func (c *Cache) ExportSprites(outputDir string) error

func (*Cache) ExportStructs

func (c *Cache) ExportStructs(outputDir string, mode JSONExportMode) error

func (*Cache) ExportTextures

func (c *Cache) ExportTextures(outputDir string, mode JSONExportMode) error

func (*Cache) Files

func (c *Cache) Files(archiveID uint8, groupID uint32) (map[uint32][]byte, error)

func (*Cache) Index

func (c *Cache) Index(archiveID uint8) (*Index, error)

func (*Cache) Item

func (c *Cache) Item(id uint16) (*Item, error)

func (*Cache) Items

func (c *Cache) Items() (map[uint16]*Item, error)

func (*Cache) NPC

func (c *Cache) NPC(id uint16) (*NPC, error)

func (*Cache) NPCs

func (c *Cache) NPCs() (map[uint16]*NPC, error)

func (*Cache) Object

func (c *Cache) Object(id uint16) (*Object, error)

func (*Cache) Objects

func (c *Cache) Objects() (map[uint16]*Object, error)

func (*Cache) Sprite

func (c *Cache) Sprite(id uint16) (*Sprite, error)

func (*Cache) Sprites

func (c *Cache) Sprites() (map[uint16]*Sprite, error)

func (*Cache) Struct

func (c *Cache) Struct(id uint16) (*Struct, error)

func (*Cache) Structs

func (c *Cache) Structs() (map[uint16]*Struct, error)

func (*Cache) Texture

func (c *Cache) Texture(id uint16) (*Texture, error)

func (*Cache) Textures

func (c *Cache) Textures() (map[uint16]*Texture, error)

type CharacterModelData

type CharacterModelData struct {
	ModelPrimary           uint16 `json:"model_primary"`
	ModelSecondary         uint16 `json:"model_secondary"`
	ModelTertiary          uint16 `json:"model_tertiary"`
	Offset                 uint8  `json:"offset"`
	ChatHeadModelPrimary   uint16 `json:"chat_head_model_primary"`
	ChatHeadModelSecondary uint16 `json:"chat_head_model_secondary"`
}

type Enum

type Enum struct {
	ID           uint16
	KeyType      byte
	ValueType    byte
	DefaultValue any
	Values       map[int32]any
}

func NewEnum

func NewEnum(id uint16) *Enum

func (*Enum) Read

func (e *Enum) Read(data []byte) error

type File

type File struct {
	ID       uint32
	NameHash int32
}

type Frame

type Frame struct {
	ID        uint16 `json:"id"`
	OffsetX   uint16 `json:"offset_x"`
	OffsetY   uint16 `json:"offset_y"`
	MaxWidth  uint16 `json:"max_width"`
	MaxHeight uint16 `json:"max_height"`
	Pixels    []byte `json:"pixels"`
	Alpha     []byte `json:"alpha"`
}

func NewFrame

func NewFrame(id uint16, offsetX uint16, offsetY uint16, maxWidth uint16, maxHeight uint16, data []byte) (*Frame, error)

func (*Frame) Read

func (f *Frame) Read(data []byte) error

type Group

type Group struct {
	ID                   uint32
	NameHash             int32
	Version              int32
	Checksum             int32
	UncompressedChecksum int32
	Length               int32
	UncompressedLength   int32
	Digest               []byte
	Files                []*File
}

func (*Group) Unpack

func (g *Group) Unpack(data []byte) (map[uint32][]byte, error)

type ImageExportable

type ImageExportable interface {
	Image() *image.RGBA
}

type ImageExporter

type ImageExporter[K comparable, V ImageExportable] struct {
	// contains filtered or unexported fields
}

func NewImageExporter

func NewImageExporter[K comparable, V ImageExportable](definitions map[K]V, outputDir string) *ImageExporter[K, V]

func (*ImageExporter[K, V]) ExportToImage

func (e *ImageExporter[K, V]) ExportToImage(prefix string) error

type Index

type Index struct {
	Protocol                 Protocol
	Version                  uint32
	HasNames                 bool
	HasDigests               bool
	HasLengths               bool
	HasUncompressedChecksums bool
	Groups                   []*Group
}

func ReadIndex

func ReadIndex(data []byte) (*Index, error)

func (*Index) Group

func (i *Index) Group(id uint32) (*Group, error)

type InventoryModelData

type InventoryModelData struct {
	ID            uint16   `json:"id"`
	Zoom          uint16   `json:"zoom"`
	RotationX     uint16   `json:"rotation_x"`
	RotationY     uint16   `json:"rotation_y"`
	RotationZ     uint16   `json:"rotation_z"`
	OffsetX       uint16   `json:"offset_x"`
	OffsetY       uint16   `json:"offset_y"`
	ScaleX        uint16   `json:"scale_x"`
	ScaleY        uint16   `json:"scale_y"`
	ScaleZ        uint16   `json:"scale_z"`
	RecolorFrom   []uint16 `json:"recolor_from"`
	RecolorTo     []uint16 `json:"recolor_to"`
	RetextureFrom []uint16 `json:"retexture_from"`
	RetextureTo   []uint16 `json:"retexture_to"`
	Ambient       int8     `json:"ambient"`
	Contrast      int8     `json:"contrast"`
}

type Item

type Item struct {
	ID                       uint16             `json:"id"`
	Category                 uint16             `json:"category"`
	Name                     string             `json:"name"`
	Examine                  string             `json:"examine"`
	MembersOnly              bool               `json:"members_only"`
	Stackable                bool               `json:"stackable"`
	Exchangeable             bool               `json:"exchangeable"`
	Value                    int32              `json:"value"`
	Weight                   int16              `json:"weight"`
	ActionsGround            [5]string          `json:"actions_ground"`
	ActionsInventory         [5]string          `json:"actions_inventory"`
	NotedItemID              uint16             `json:"noted_item_id"`
	NotedTemplate            uint16             `json:"noted_template"`
	StackItemIDs             [10]uint16         `json:"stack_item_ids"`
	StackQuantities          [10]uint16         `json:"stack_quantities"`
	Team                     int8               `json:"team"`
	BoughtLinkID             uint16             `json:"bought_link_id"`
	BoughtTemplate           uint16             `json:"bought_template"`
	PlaceholderItemID        uint16             `json:"placeholder_item_id"`
	PlaceholderTemplate      uint16             `json:"placeholder_template"`
	ShiftClickDropIndex      uint8              `json:"shift_click_drop_index"`
	Params                   map[uint32]any     `json:"params"`
	InventoryModelData       InventoryModelData `json:"inventory_model_data"`
	CharacterModelDataMale   CharacterModelData `json:"character_model_data_male"`
	CharacterModelDataFemale CharacterModelData `json:"character_model_data_female"`
	WearPositionPrimary      uint8              `json:"wear_position_primary"`
	WearPositionSecondary    uint8              `json:"wear_position_secondary"`
	WearPositionTertiary     uint8              `json:"wear_position_tertiary"`
}

func NewItem

func NewItem(id uint16) *Item

func (*Item) Read

func (item *Item) Read(data []byte) error

type JSONExportMode

type JSONExportMode string
const (
	JsonExportModeSingle     JSONExportMode = "single"
	JsonExportModeIndividual JSONExportMode = "individual"
)

type JSONExporter

type JSONExporter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewJSONExporter

func NewJSONExporter[K comparable, V any](definitions map[K]V, outputDir string) *JSONExporter[K, V]

func (*JSONExporter[K, V]) ExportAll

func (e *JSONExporter[K, V]) ExportAll(filename string) error

func (*JSONExporter[K, V]) ExportIndividual

func (e *JSONExporter[K, V]) ExportIndividual(prefix string) error

func (*JSONExporter[K, V]) ExportToJSON

func (e *JSONExporter[K, V]) ExportToJSON(mode JSONExportMode, filename string) error

type NPC

type NPC struct {
	ID               uint16           `json:"id"`
	Category         uint16           `json:"category"`
	Name             string           `json:"name"`
	Examine          string           `json:"examine"`
	Size             uint8            `json:"size"`
	Height           uint16           `json:"height"`
	Hitpoints        uint16           `json:"hitpoints"`
	Attack           uint16           `json:"attack"`
	Strength         uint16           `json:"strength"`
	Defense          uint16           `json:"defense"`
	Ranged           uint16           `json:"ranged"`
	Magic            uint16           `json:"magic"`
	CombatLevel      uint16           `json:"combat_level"`
	Actions          [5]string        `json:"actions"`
	Interactable     bool             `json:"interactable"`
	Follower         bool             `json:"follower"`
	LowPriority      bool             `json:"low_priority"`
	Visible          bool             `json:"visible"`
	VisibleOnMinimap bool             `json:"visible_on_minimap"`
	Configs          []uint16         `json:"configs"`
	VarbitID         uint16           `json:"varbit_id"`
	VarpIndex        uint16           `json:"varp_index"`
	OobChild         uint16           `json:"oob_child"`
	Params           map[uint32]any   `json:"params"`
	ModelData        NPCModelData     `json:"model_data"`
	AnimationData    NPCAnimationData `json:"animation_data"`
}

func NewNPC

func NewNPC(id uint16) *NPC

func (*NPC) Read

func (npc *NPC) Read(data []byte) error

type NPCAnimationData

type NPCAnimationData struct {
	Idle                uint16 `json:"idle"`
	IdleRotateLeft      uint16 `json:"idle_rotate_left"`
	IdleRotateRight     uint16 `json:"idle_rotate_right"`
	Walking             uint16 `json:"walking"`
	WalkingRotateLeft   uint16 `json:"walking_rotate_left"`
	WalkingRotateRight  uint16 `json:"walking_rotate_right"`
	WalkingRotate180    uint16 `json:"walking_rotate_180"`
	Running             uint16 `json:"running"`
	RunningRotateLeft   uint16 `json:"running_rotate_left"`
	RunningRotateRight  uint16 `json:"running_rotate_right"`
	RunningRotate180    uint16 `json:"running_rotate_180"`
	Crawling            uint16 `json:"crawling"`
	CrawlingRotateLeft  uint16 `json:"crawling_rotate_left"`
	CrawlingRotateRight uint16 `json:"crawling_rotate_right"`
	CrawlingRotate180   uint16 `json:"crawling_rotate_180"`
}

type NPCModelData

type NPCModelData struct {
	Models              []uint16 `json:"models"`
	ChatHeadModels      []uint16 `json:"chat_head_models"`
	RecolorFrom         []uint16 `json:"recolor_from"`
	RecolorTo           []uint16 `json:"recolor_to"`
	RetextureFrom       []uint16 `json:"retexture_from"`
	RetextureTo         []uint16 `json:"retexture_to"`
	ScaleHeight         uint16   `json:"scale_height"`
	ScaleWidth          uint16   `json:"scale_width"`
	RenderPriority      bool     `json:"render_priority"`
	Ambient             uint8    `json:"ambient"`
	Contrast            uint8    `json:"contrast"`
	HeadIcon            uint16   `json:"head_icon"`
	HeadIconArchive     []int16  `json:"head_icon_archive"`
	HeadIconSpriteIndex []int16  `json:"head_icon_sprite_index"`
	RotateSpeed         uint16   `json:"rotate_speed"`
	RotateFlag          bool     `json:"rotate_flag"`
}

type Object

type Object struct {
	ID                         uint16          `json:"id"`
	Category                   uint16          `json:"category"`
	Name                       string          `json:"name"`
	ConfigID                   uint16          `json:"config_id"`
	MapAreaID                  uint16          `json:"map_area_id"`
	MapSceneID                 uint16          `json:"map_scene_id"`
	AnimationID                uint16          `json:"animation_id"`
	Solid                      bool            `json:"solid"`
	Shadow                     bool            `json:"shadow"`
	ObstructGround             bool            `json:"obstruct_ground"`
	SupportsItems              uint8           `json:"supports_items"`
	Actions                    [5]string       `json:"actions"`
	InteractType               uint8           `json:"interact_type"`
	Rotated                    bool            `json:"rotated"`
	AmbientSoundID             uint16          `json:"ambient_sound_id"`
	AmbientSoundIDs            []uint16        `json:"ambient_sound_ids"`
	AmbientSoundDistance       uint8           `json:"ambient_sound_distance"`
	AmbientSoundRetain         uint8           `json:"ambient_sound_retain"`
	AmbientSoundChangeTicksMin uint16          `json:"ambient_sound_change_ticks_min"`
	AmbientSoundChangeTicksMax uint16          `json:"ambient_sound_change_ticks_max"`
	BlocksProjectile           bool            `json:"blocks_projectile"`
	WallOrDoor                 uint8           `json:"wall_or_door"`
	ContouredGround            uint8           `json:"contoured_ground"`
	ConfigChangeDest           []uint16        `json:"config_change_dest"`
	Params                     map[uint32]any  `json:"params"`
	ModelData                  ObjectModelData `json:"model_data"`
}

func NewObject

func NewObject(id uint16) *Object

func (*Object) Read

func (obj *Object) Read(data []byte) error

type ObjectModelData

type ObjectModelData struct {
	Models             []uint16 `json:"models"`
	Types              []uint8  `json:"types"`
	RecolorFrom        []uint16 `json:"recolor_from"`
	RecolorTo          []uint16 `json:"recolor_to"`
	RetextureFrom      []uint16 `json:"retexture_from"`
	RetextureTo        []uint16 `json:"retexture_to"`
	SizeX              uint8    `json:"size_x"`
	SizeY              uint8    `json:"size_y"`
	OffsetX            uint16   `json:"offset_x"`
	OffsetY            uint16   `json:"offset_y"`
	OffsetZ            uint16   `json:"offset_z"`
	ModelSizeX         uint16   `json:"model_size_x"`
	ModelSizeY         uint16   `json:"model_size_y"`
	ModelSizeZ         uint16   `json:"model_size_z"`
	VarpID             uint16   `json:"varp_id"`
	Ambient            uint8    `json:"ambient"`
	Contrast           uint8    `json:"contrast"`
	DecordDisplacement uint8    `json:"decord_displacement"`
	MergeNormals       bool     `json:"merge_normals"`
	BlockingMask       uint8    `json:"blocking_mask"`
}

type Protocol

type Protocol uint8
const (
	ProtocolOriginal Protocol = iota + 5
	ProtocolVersioned
	ProtocolSmart
)

func ProtocolFromID

func ProtocolFromID(id uint8) (Protocol, error)

type Reader

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

func NewReader

func NewReader(data []byte) *Reader

func (*Reader) Len

func (r *Reader) Len() int

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) ReadBigSmart2

func (r *Reader) ReadBigSmart2() (int32, error)

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(n int) ([]byte, error)

func (*Reader) ReadInt16

func (r *Reader) ReadInt16() (int16, error)

func (*Reader) ReadInt32

func (r *Reader) ReadInt32() (int32, error)

func (*Reader) ReadInt8

func (r *Reader) ReadInt8() (int8, error)

func (*Reader) ReadSmartUint

func (r *Reader) ReadSmartUint() (uint32, error)

func (*Reader) ReadString

func (r *Reader) ReadString() (string, error)

func (*Reader) ReadUint16

func (r *Reader) ReadUint16() (uint16, error)

func (*Reader) ReadUint16SmartMinus1

func (r *Reader) ReadUint16SmartMinus1() (uint16, error)

func (*Reader) ReadUint24

func (r *Reader) ReadUint24() (uint32, error)

func (*Reader) ReadUint32

func (r *Reader) ReadUint32() (uint32, error)

func (*Reader) ReadUint8

func (r *Reader) ReadUint8() (uint8, error)

func (*Reader) Reset

func (r *Reader) Reset(b []byte)

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

func (*Reader) Size

func (r *Reader) Size() int64

type Sprite

type Sprite struct {
	ID      uint16   `json:"id"`
	Width   uint16   `json:"width"`
	Height  uint16   `json:"height"`
	Palette []uint32 `json:"palette"`
	Frames  []*Frame `json:"frames"`
}

func NewSprite

func NewSprite(id uint16) *Sprite

func (*Sprite) Image

func (s *Sprite) Image() *image.RGBA

func (*Sprite) Read

func (s *Sprite) Read(data []byte) error

type Store

type Store interface {
	ArchiveList() ([]uint8, error)
	ArchiveExists(archiveID uint8) bool
	GroupList(archiveID uint8) ([]uint32, error)
	GroupExists(archiveID uint8, groupID uint32) bool
	Read(archiveID uint8, groupID uint32) ([]byte, error)
}

type Struct

type Struct struct {
	ID     uint16
	Params map[uint32]any
}

func NewStruct

func NewStruct(id uint16) *Struct

func (*Struct) Read

func (s *Struct) Read(data []byte) error

type Texture

type Texture struct {
	ID                 uint16
	SpriteIDs          []uint16
	Opaque             bool    // Not 100% sure this is Opaque
	Colors             []int32 // Not 100% sure this is Colors
	AverageRGB         uint16  // Not 100% sure this is AverageRGB
	BlendModes         []uint8 // Not 100% sure this is BlendModes
	AnimationSpeed     uint8
	AnimationDirection uint8
	AnimationFrames    []uint8 // Not 100% sure this is AnimationFrames
}

func NewTexture

func NewTexture(id uint16) *Texture

func (*Texture) Read

func (t *Texture) Read(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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