Documentation
¶
Index ¶
- Constants
- func ComputeCRC32(data []byte) uint32
- func GetCipherPassword() string
- func GetResourceId(dir CentralDir, fileName string) int32
- func LoadDataFromResource(chunk ResourceChunk) []byte
- func LoadFontFromResource(multi ResourceMulti) rl.Font
- func LoadImageFromResource(chunk ResourceChunk) rl.Image
- func LoadMeshFromResource(multi ResourceMulti) rl.Mesh
- func LoadTextFromResource(chunk ResourceChunk) string
- func LoadWaveFromResource(chunk ResourceChunk) rl.Wave
- func SetBaseDirectory(baseDir string)
- func SetCipherPassword(pass string)
- func UnloadCentralDirectory(dir *CentralDir)
- func UnloadResourceChunk(chunk *ResourceChunk)
- func UnloadResourceMulti(multi *ResourceMulti)
- func WipeCipherPassword()
- type CentralDir
- type CodeLang
- type CompressionType
- type DirEntry
- type EncryptionType
- type ErrorType
- type FileHeader
- type FontGlyphInfo
- type FontStyle
- type PixelFormat
- type ResourceChunk
- type ResourceChunkData
- type ResourceChunkInfo
- type ResourceDataType
- type ResourceMulti
- type TextEncoding
- type VertexAttribute
- type VertexFormat
Constants ¶
const MaxFilenameSize = 1024
Variables ¶
This section is empty.
Functions ¶
func ComputeCRC32 ¶
ComputeCRC32 - Compute CRC32 hash
NOTE: CRC32 is used as rres id, generated from original filename
func GetCipherPassword ¶
func GetCipherPassword() string
GetCipherPassword - Get password to be used on data decryption
func GetResourceId ¶
func GetResourceId(dir CentralDir, fileName string) int32
GetResourceId - Get resource id for a provided filename
NOTE: It requires CDIR available in the file (it's optinal by design)
func LoadDataFromResource ¶
func LoadDataFromResource(chunk ResourceChunk) []byte
LoadDataFromResource - Load raw data from rres resource chunk
NOTE: Chunk data must be provided uncompressed/unencrypted
func LoadFontFromResource ¶
func LoadFontFromResource(multi ResourceMulti) rl.Font
LoadFontFromResource - Load Font data from rres resource multiple chunks
func LoadImageFromResource ¶
func LoadImageFromResource(chunk ResourceChunk) rl.Image
LoadImageFromResource - Load Image data from rres resource chunk
func LoadMeshFromResource ¶
func LoadMeshFromResource(multi ResourceMulti) rl.Mesh
LoadMeshFromResource - Load Mesh data from rres resource multiple chunks
func LoadTextFromResource ¶
func LoadTextFromResource(chunk ResourceChunk) string
LoadTextFromResource - Load text data from rres resource chunk
func LoadWaveFromResource ¶
func LoadWaveFromResource(chunk ResourceChunk) rl.Wave
LoadWaveFromResource - Load Wave data from rres resource chunk
func SetBaseDirectory ¶
func SetBaseDirectory(baseDir string)
SetBaseDirectory - Set base directory for externally linked data
NOTE: When resource chunk contains an external link (FourCC: LINK, Type: RRES_DATA_LINK), a base directory is required to be prepended to link path
If not provided, the application path is prepended to link by default
func SetCipherPassword ¶
func SetCipherPassword(pass string)
SetCipherPassword - Set password to be used on data decryption
NOTE: The cipher password is kept as an internal pointer to provided string, it's up to the user to manage that sensible data properly
Password should be to allocate and set before loading an encrypted resource and it should be cleaned/wiped after the encrypted resource has been loaded
You can use the WipeCipherPassword function to clear the password
func UnloadCentralDirectory ¶
func UnloadCentralDirectory(dir *CentralDir)
UnloadCentralDirectory - Unload central directory resource chunk
func UnloadResourceChunk ¶
func UnloadResourceChunk(chunk *ResourceChunk)
UnloadResourceChunk - Unload resource chunk from memory
func UnloadResourceMulti ¶
func UnloadResourceMulti(multi *ResourceMulti)
UnloadResourceMulti - Unload resource from memory (multiple resource chunks)
func WipeCipherPassword ¶
func WipeCipherPassword()
WipeCipherPassword - Clears the password from the C memory using explicit_bzero
This is an approach but no guarantee
Types ¶
type CentralDir ¶
type CentralDir struct { Count uint32 // Central directory entries count // contains filtered or unexported fields }
CentralDir - CDIR: rres central directory
NOTE: This data conforms the ResourceChunkData
func LoadCentralDirectory ¶
func LoadCentralDirectory(fileName string) CentralDir
LoadCentralDirectory - Load central directory resource chunk from file
func (*CentralDir) Entries ¶
func (c *CentralDir) Entries() []DirEntry
Entries - Central directory entries
type CodeLang ¶
type CodeLang int32
CodeLang - TEXT: Text code language
NOTE: It could be useful for code script resources
const ( CodeLangUndefined CodeLang = iota // Undefined code language, text is plain text CodeLangC // Text contains C code CodeLangCpp // Text contains C++ code CodeLangCs // Text contains C# code CodeLangLua // Text contains Lua code CodeLangJs // Text contains JavaScript code CodeLangPython // Text contains Python code CodeLangRust // Text contains Rust code CodeLangZig // Text contains Zig code CodeLangOdin // Text contains Odin code CodeLangJai // Text contains Jai code CodeLangGdscript // Text contains GDScript (Godot) code CodeLangGlsl // Text contains GLSL shader code )
type CompressionType ¶
type CompressionType int32
CompressionType - Compression algorithms
value required by ResourceChunkInfo.CompType
NOTE 1: This enum just lists some common data compression algorithms for convenience, The rres packer tool and the engine-specific library are responsible to implement the desired ones,
NOTE 2: ResourceChunkInfo.CompType is a byte-size value, limited to [0..255]
const ( CompNone CompressionType = 0 // No data compression CompRle CompressionType = 1 // RLE compression CompDeflate CompressionType = 10 // DEFLATE compression CompLz4 CompressionType = 20 // LZ4 compression CompLzma2 CompressionType = 30 // LZMA2 compression CompQoi CompressionType = 40 // QOI compression, useful for RGB(A) image data )
type DirEntry ¶
type DirEntry struct { Id uint32 // Resource id Offset uint32 // Resource global offset in file Reserved uint32 // reserved FileNameSize uint32 // Resource fileName size (NULL terminator and 4-byte alignment padding considered) // contains filtered or unexported fields }
DirEntry - CDIR: rres central directory entry
type EncryptionType ¶
type EncryptionType int32
EncryptionType - Encryption algorithms
value required by ResourceChunkInfo.CipherType
NOTE 1: This enum just lists some common data encryption algorithms for convenience, The rres packer tool and the engine-specific library are responsible to implement the desired ones,
NOTE 2: Some encryption algorithms could require/generate additional data (seed, salt, nonce, MAC...) in those cases, that extra data must be appended to the original encrypted message and added to the resource data chunk
NOTE 3: ResourceChunkInfo.CipherType is a byte-size value, limited to [0..255]
const ( CipherNone EncryptionType = 0 // No data encryption CipherXor EncryptionType = 1 // XOR encryption, generic using 128bit key in blocks CipherDes EncryptionType = 10 // DES encryption CipherTdes EncryptionType = 11 // Triple DES encryption CipherIdea EncryptionType = 20 // IDEA encryption CipherAes EncryptionType = 30 // AES (128bit or 256bit) encryption CipherAesGCM EncryptionType = 31 // AES Galois/Counter Mode (Galois Message Authentication Code - GMAC) CipherXtea EncryptionType = 40 // XTEA encryption CipherBlowfish EncryptionType = 50 // BLOWFISH encryption CipherRsa EncryptionType = 60 // RSA asymmetric encryption CipherSalsa20 EncryptionType = 70 // SALSA20 encryption CipherChacha20 EncryptionType = 71 // CHACHA20 encryption CipherXchacha20 EncryptionType = 72 // XCHACHA20 encryption CipherXchacha20Poly1305 EncryptionType = 73 // XCHACHA20 with POLY1305 for message authentication (MAC) )
type ErrorType ¶
type ErrorType int32
ErrorType - error codes
NOTE: Error codes when processing rres files
const ( Success ErrorType = iota // rres file loaded/saved successfully ErrorFileNotFound // rres file can not be opened (spelling issues, file actually does not exist...) ErrorFileFormat // rres file format not a supported (wrong header, wrong identifier) ErrorMemoryAlloc // Memory could not be allocated for operation. )
func UnpackResourceChunk ¶
func UnpackResourceChunk(chunk *ResourceChunk) ErrorType
UnpackResourceChunk - Unpack resource chunk data (decompres/decrypt data)
NOTE: Function return 0 on success or other value on failure
type FileHeader ¶
type FileHeader struct { Id [4]byte // File identifier: rres Version uint16 // File version: 100 for version 1.0 ChunkCount uint16 // Number of resource chunks in the file (MAX: 65535) CdOffset uint32 // Central Directory offset in file (0 if not available) Reserved uint32 // <reserved> }
FileHeader - (16 bytes)
type FontGlyphInfo ¶
type FontGlyphInfo struct {
X, Y, Width, Height int32 // Glyph rectangle in the atlas image
Value int32 // Glyph codepoint value
OffsetX, OffsetY int32 // Glyph drawing offset (from base line)
AdvanceX int32 // Glyph advance X for next character
}
FontGlyphInfo - FNTG: rres font glyphs info (32 bytes)
NOTE: Array of this type conforms the ResourceChunkData
type PixelFormat ¶
type PixelFormat int32
PixelFormat - IMGE: Image/Texture pixel formats
const ( PixelFormatUndefined PixelFormat = iota // Undefined pixel format PixelFormatUncompGrayscale // 8 bit per pixel (no alpha) PixelFormatUncompGrayAlpha // 16 bpp (2 channels) PixelFormatUncompR5g6b5 // 16 bpp PixelFormatUncompR8g8b8 // 24 bpp PixelFormatUncompR5g5b5a1 // 16 bpp (1 bit alpha) PixelFormatUncompR4g4b4a4 // 16 bpp (4 bit alpha) PixelFormatUncompR8g8b8a8 // 32 bpp PixelFormatUncompR32 // 32 bpp (1 channel - float) PixelFormatUncompR32g32b32 // 32*3 bpp (3 channels - float) PixelFormatUncompR32g32b32a32 // 32*4 bpp (4 channels - float) PixelFormatCompDxt1Rgb // 4 bpp (no alpha) PixelFormatCompDxt1Rgba // 4 bpp (1 bit alpha) PixelFormatCompDxt3Rgba // 8 bpp PixelFormatCompDxt5Rgba // 8 bpp PixelFormatCompEtc1Rgb // 4 bpp PixelFormatCompEtc2Rgb // 4 bpp PixelFormatCompEtc2EacRgba // 8 bpp PixelFormatCompPvrtRgb // 4 bpp PixelFormatCompPvrtRgba // 4 bpp PixelFormatCompAtsc4x4Rgba // 8 bpp PixelFormatCompAtsc8x8Rgba // 2 bpp )
type ResourceChunk ¶
type ResourceChunk struct { Info ResourceChunkInfo // Resource chunk info Data ResourceChunkData // Resource chunk packed data, contains propCount, props[] and raw data }
ResourceChunk
func LoadResourceChunk ¶
func LoadResourceChunk(fileName string, rresId int32) ResourceChunk
LoadResourceChunk - Load one resource chunk for provided id
type ResourceChunkData ¶
type ResourceChunkData struct { PropCount uint32 // Resource chunk properties count Props *uint32 // Resource chunk properties Raw unsafe.Pointer // Resource chunk raw data }
ResourceChunkData
type ResourceChunkInfo ¶
type ResourceChunkInfo struct { Type [4]byte // Resource chunk type (FourCC) Id uint32 // Resource chunk identifier (generated from filename CRC32 hash) CompType byte // Data compression algorithm CipherType byte // Data encryption algorithm Flags uint16 // Data flags (if required) PackedSize uint32 // Data chunk size (compressed/encrypted + custom data appended) BaseSize uint32 // Data base size (uncompressed/unencrypted) NextOffset uint32 // Next resource chunk global offset (if resource has multiple chunks) Reserved uint32 // <reserved> Crc32 uint32 // Data chunk CRC32 (propCount + props[] + data) }
ResourceChunkInfo - header (32 bytes)
func LoadResourceChunkInfo ¶
func LoadResourceChunkInfo(fileName string, rresId int32) ResourceChunkInfo
LoadResourceChunkInfo - Load resource chunk info for provided id
func LoadResourceChunkInfoAll ¶
func LoadResourceChunkInfoAll(fileName string) []ResourceChunkInfo
LoadResourceChunkInfoAll - Load all resource chunks info
type ResourceDataType ¶
type ResourceDataType int32
ResourceDataType
NOTE 1: Data type determines the properties and the data included in every chunk
NOTE 2: This enum defines the basic resource data types, some input files could generate multiple resource chunks:
Fonts processed could generate (2) resource chunks: - [FNTG] rres[0]: RRES_DATA_FONT_GLYPHS - [IMGE] rres[1]: RRES_DATA_IMAGE Mesh processed could generate (n) resource chunks: - [VRTX] rres[0]: RRES_DATA_VERTEX ... - [VRTX] rres[n]: RRES_DATA_VERTEX
const ( // FourCC: NULL - Reserved for empty chunks, no props/data DataNull ResourceDataType = iota // FourCC: RAWD - Raw file data, 4 properties // props[0]:size (bytes) // props[1]:extension01 (big-endian: ".png" = 0x2e706e67) // props[2]:extension02 (additional part, extensions with +3 letters) // props[3]:reserved // data: raw bytes DataRaw // FourCC: TEXT - Text file data, 4 properties // props[0]:size (bytes) // props[1]:rresTextEncoding // props[2]:rresCodeLang // props[3]:cultureCode // data: text DataText // FourCC: IMGE - Image file data, 4 properties // props[0]:width // props[1]:height // props[2]:rresPixelFormat // props[3]:mipmaps // data: pixels DataImage // FourCC: WAVE - Audio file data, 4 properties // props[0]:frameCount // props[1]:sampleRate // props[2]:sampleSize // props[3]:channels // data: samples DataWave // FourCC: VRTX - Vertex file data, 4 properties // props[0]:vertexCount // props[1]:rresVertexAttribute // props[2]:componentCount // props[3]:rresVertexFormat // data: vertex DataVertex // FourCC: FNTG - Font glyphs info data, 4 properties // props[0]:baseSize // props[1]:glyphCount // props[2]:glyphPadding // props[3]:rresFontStyle // data: rresFontGlyphInfo[0..glyphCount] DataFontGlyphs // FourCC: LINK - External linked file, 1 property // props[0]:size (bytes) // data: filepath (as provided on input) DataLink ResourceDataType = 99 // FourCC: CDIR - Central directory for input files // props[0]:entryCount, 1 property // data: rresDirEntry[0..entryCount] DataDirectory ResourceDataType = 100 )
func GetDataType ¶
func GetDataType(fourCC [4]byte) ResourceDataType
GetDataType - Get ResourceDataType from FourCC code
type ResourceMulti ¶
type ResourceMulti struct { Count uint32 // Resource chunks count // contains filtered or unexported fields }
ResourceMulti
NOTE: It supports multiple resource chunks
func LoadResourceMulti ¶
func LoadResourceMulti(fileName string, rresId int32) ResourceMulti
LoadResourceMulti - Load resource for provided id (multiple resource chunks)
func (*ResourceMulti) Chunks ¶
func (r *ResourceMulti) Chunks() []ResourceChunk
Chunks - Resource chunks
type TextEncoding ¶
type TextEncoding int32
TextEncoding - TEXT: Text encoding property values
const ( TextEncodingUndefined TextEncoding = 0 // Not defined, usually UTF-8 TextEncodingUtf8 TextEncoding = 1 // UTF-8 text encoding TextEncodingUtf8Bom TextEncoding = 2 // UTF-8 text encoding with Byte-Order-Mark TextEncodingUtf16Le TextEncoding = 10 // UTF-16 Little Endian text encoding TextEncodingUtf16Be TextEncoding = 11 // UTF-16 Big Endian text encoding )
type VertexAttribute ¶
type VertexAttribute int32
VertexAttribute - VRTX: Vertex data attribute
NOTE: The expected number of components for every vertex attribute is provided as a property to data, the listed components count are the expected/default ones
const ( VertexAttributePosition VertexAttribute = 0 // Vertex position attribute: [x, y, z] VertexAttributeTexcoord1 VertexAttribute = 10 // Vertex texture coordinates attribute: [u, v] VertexAttributeTexcoord2 VertexAttribute = 11 // Vertex texture coordinates attribute: [u, v] VertexAttributeTexcoord3 VertexAttribute = 12 // Vertex texture coordinates attribute: [u, v] VertexAttributeTexcoord4 VertexAttribute = 13 // Vertex texture coordinates attribute: [u, v] VertexAttributeNormal VertexAttribute = 20 // Vertex normal attribute: [x, y, z] VertexAttributeTangent VertexAttribute = 30 // Vertex tangent attribute: [x, y, z, w] VertexAttributeColor VertexAttribute = 40 // Vertex color attribute: [r, g, b, a] VertexAttributeIndex VertexAttribute = 100 // Vertex index attribute: [i] )
type VertexFormat ¶
type VertexFormat int32
VertexFormat - VRTX: Vertex data format type
const ( VertexFormatUbyte VertexFormat = iota // 8 bit unsigned integer data VertexFormatByte // 8 bit signed integer data VertexFormatUshort // 16 bit unsigned integer data VertexFormatShort // 16 bit signed integer data VertexFormatUint // 32 bit unsigned integer data VertexFormatInt // 32 bit integer data VertexFormatHfloat // 16 bit float data VertexFormatFloat // 32 bit float data )