Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeCatalog(cat *AssetBundleCatalog) ([]byte, error)
- func EncodeExtensionNameList(value *ExtensionNameList) ([]byte, error)
- func HashBytes(bytes []byte) uint64
- func HashString(text string) uint64
- func HashStringIgnoreCase(text string) uint64
- func ValidateCatalog(cat *AssetBundleCatalog) error
- func ValidateExtensionNameList(value *ExtensionNameList) error
- func WriteContentTable(w io.Writer, ct *ContentTable) error
- type AssetBundleCatalog
- func DecodeCatalog(data []byte) (*AssetBundleCatalog, error)
- func DecodeCatalogFromCt(table *ContentTable) (*AssetBundleCatalog, error)
- func DecodeCatalogFromCtWithKind(table *ContentTable, kind CatalogKind) (*AssetBundleCatalog, error)
- func DecodeCatalogWithKind(data []byte, kind CatalogKind) (*AssetBundleCatalog, error)
- type CatalogItem
- type CatalogKind
- type CatalogPackageType
- type CatalogType
- type ContentTable
- func (ct *ContentTable) AddFile(name string, data []byte) error
- func (ct *ContentTable) DecodeMsgpackFile(name string, out interface{}) error
- func (ct *ContentTable) GetFileData(name string) ([]byte, error)
- func (ct *ContentTable) GetFileNames() []string
- func (ct *ContentTable) GetVirtualDirectoryMetadata() map[string]VirtualDirectoryMetadata
- type ExtensionNameList
- type ExtensionNamePack
- type VirtualCatalogItem
- type VirtualDirectoryFraming
- type VirtualDirectoryMetadata
- type VirtualFile
Constants ¶
const ( // HeaderSize 是文件头大小,由 7 字节签名和 1 字节序列化类型组成 // HeaderSize is the header width made up of a 7-byte signature and a 1-byte serialization type HeaderSize = 8 // SerializeTypeMsgPack 表示带 UInt32 长度尾部的旧 MessagePack 封装 // SerializeTypeMsgPack selects the legacy MessagePack frame with a trailing UInt32 length SerializeTypeMsgPack byte = 0x8e // SerializeTypeMsgPackExtended 表示带 UInt64 长度与固定签名尾部的扩展 MessagePack 封装 // SerializeTypeMsgPackExtended selects the extended MessagePack frame with a trailing UInt64 length and fixed signature SerializeTypeMsgPackExtended byte = 0xff )
Variables ¶
var FileSignature = []byte{0xbb, 0xc3, 0xaa, 0x9a, 0xa6, 0x4d, 0xad}
FileSignature 是 .ct 文件的魔数签名(7 字节),用于验证文件格式 对应 C# VirtualDirectory.FileSignature = {0xbb, 0xc3, 0xaa, 0x9a, 0xa6, 0x4d, 0xad} FileSignature is the 7-byte magic signature used to validate .ct files It matches C# VirtualDirectory.FileSignature = {0xbb, 0xc3, 0xaa, 0x9a, 0xa6, 0x4d, 0xad}
Functions ¶
func EncodeCatalog ¶
func EncodeCatalog(cat *AssetBundleCatalog) ([]byte, error)
EncodeCatalog 按 Kind 选择固定布局并编码唯一完整的 catalog 根值 EncodeCatalog selects the fixed layout by Kind and encodes the sole complete catalog root
func EncodeExtensionNameList ¶
func EncodeExtensionNameList(value *ExtensionNameList) ([]byte, error)
EncodeExtensionNameList 编码唯一完整的固定两槽 ExtensionNameList 根值 EncodeExtensionNameList encodes the sole complete fixed two-slot ExtensionNameList root
func HashBytes ¶
HashBytes 计算字节序列的 FNV-1a 64-bit 哈希,空输入返回零 对应 C# AssetManager.GetHash(byte[]) HashBytes computes the FNV-1a 64-bit hash of a byte sequence and returns zero for empty input It corresponds to C# AssetManager.GetHash(byte[])
func HashString ¶
HashString 对字符串 UTF-8 编码后计算区分大小写的 FNV-1a 64-bit 哈希,空字符串返回零 对应 C# AssetManager.GetHash(string):先 UTF-8 编码再哈希 HashString computes a case-sensitive FNV-1a 64-bit hash after UTF-8 encoding a string and returns zero for an empty string It corresponds to C# AssetManager.GetHash(string), which encodes as UTF-8 before hashing
func HashStringIgnoreCase ¶
HashStringIgnoreCase 计算与 C# AssetManager.GetHashIgnoreCase(string) 一致的忽略大小写 FNV-1a 64-bit 哈希,空字符串返回零 算法逐个处理 UTF-16 code unit,ASCII 大写先转小写,非 ASCII code unit 使用 ToLowerInvariant 后按游戏分支写入两个或三个 UTF-8 形式字节 HashStringIgnoreCase computes the case-insensitive FNV-1a 64-bit hash matching C# AssetManager.GetHashIgnoreCase(string) and returns zero for an empty string The algorithm processes UTF-16 code units individually, lower-cases ASCII directly, and applies ToLowerInvariant to non-ASCII code units before writing two or three UTF-8-form bytes through the game branches
func ValidateCatalog ¶
func ValidateCatalog(cat *AssetBundleCatalog) error
ValidateCatalog 校验 catalog 的具体类型、互斥字段和 UTF-8 字符串 ValidateCatalog validates a catalog's concrete type, mutually exclusive fields, and UTF-8 strings
func ValidateExtensionNameList ¶
func ValidateExtensionNameList(value *ExtensionNameList) error
ValidateExtensionNameList 校验 ExtensionNameList 的 UTF-8 字符串字段 ValidateExtensionNameList validates the UTF-8 string fields of an ExtensionNameList
func WriteContentTable ¶
func WriteContentTable(w io.Writer, ct *ContentTable) error
WriteContentTable 将 ContentTable 序列化为 .ct 格式并写入 writer 写入顺序为签名、序列化类型、各文件原始数据、LZ4 压缩的 VirtualDirectory 和长度尾部 WriteContentTable serializes ContentTable in .ct format and writes it to writer The write order is the signature, serialization type, raw file data, LZ4-compressed VirtualDirectory, and trailing length
Types ¶
type AssetBundleCatalog ¶
type AssetBundleCatalog struct {
Kind CatalogKind `json:"kind"` // 具体 catalog 类型 / Concrete catalog type
Version int32 `json:"version"` // 序列化版本 / Serialization version
CatalogType CatalogType `json:"catalogType"` // 资源分类标志位 / Resource-category flags
PackageType CatalogPackageType `json:"packageType"` // catalog 包类型 / Catalog package type
Priority int32 `json:"priority"` // catalog 排序优先级 / Catalog ordering priority
Name *string `json:"name"` // catalog 名称 / Catalog name
SubName *string `json:"subName"` // catalog 子名称 / Catalog sub-name
Hash uint64 `json:"hash"` // catalog 哈希 / Catalog hash
CreateTime int64 `json:"createTime"` // 创建时间 / Creation time
IsEncrypted bool `json:"isEncrypted,omitempty"` // AssetBundle 是否加密 / Whether AssetBundles are encrypted
ResourceFileNames []*string `json:"resourceFileNames,omitempty"` // AssetBundle 资源文件名 / AssetBundle resource file names
ExtensionList []*string `json:"extensionList"` // 扩展名虚拟文件列表 / Extension-name virtual-file list
Items []*CatalogItem `json:"items,omitempty"` // AssetBundle catalog 条目 / AssetBundle catalog items
VirtualItems []*VirtualCatalogItem `json:"virtualItems,omitempty"` // VirtualAsset catalog 条目 / VirtualAsset catalog items
}
AssetBundleCatalog 表示游戏的 AssetBundleCatalog 或 VirtualAssetCatalog Kind 明确选择固定十二槽 AssetBundle 布局或固定十槽 VirtualAsset 布局 AssetBundleCatalog represents the game's AssetBundleCatalog or VirtualAssetCatalog Kind explicitly selects the fixed twelve-slot AssetBundle layout or fixed ten-slot VirtualAsset layout
func DecodeCatalog ¶
func DecodeCatalog(data []byte) (*AssetBundleCatalog, error)
DecodeCatalog 解码唯一完整的 catalog 根值并按固定宽度识别具体类型 DecodeCatalog decodes the sole complete catalog root and identifies its concrete type by fixed width
func DecodeCatalogFromCt ¶
func DecodeCatalogFromCt(table *ContentTable) (*AssetBundleCatalog, error)
DecodeCatalogFromCt 从 .ct 的 catalog 虚拟文件解码具体 catalog DecodeCatalogFromCt decodes the concrete catalog from the catalog virtual file in a .ct container
func DecodeCatalogFromCtWithKind ¶
func DecodeCatalogFromCtWithKind(table *ContentTable, kind CatalogKind) (*AssetBundleCatalog, error)
DecodeCatalogFromCtWithKind 从 .ct 的 catalog 虚拟文件按指定类型解码 DecodeCatalogFromCtWithKind decodes the caller-selected catalog type from the catalog virtual file in a .ct container
func DecodeCatalogWithKind ¶
func DecodeCatalogWithKind(data []byte, kind CatalogKind) (*AssetBundleCatalog, error)
DecodeCatalogWithKind 按调用方指定的具体 catalog 类型解码并验证固定宽度 DecodeCatalogWithKind decodes the caller-selected concrete catalog type and validates its fixed width
func (AssetBundleCatalog) MarshalJSON ¶
func (cat AssetBundleCatalog) MarshalJSON() ([]byte, error)
MarshalJSON 仅写出 Kind 对应 catalog 布局的真实字段并让活动可空切片显式成为 JSON null MarshalJSON emits only the real fields of the catalog layout selected by Kind and represents active nullable slices as explicit JSON null
func (*AssetBundleCatalog) UnmarshalJSON ¶
func (cat *AssetBundleCatalog) UnmarshalJSON(data []byte) error
UnmarshalJSON 严格解码 catalog union,要求当前布局的全部分支字段出现并拒绝另一布局的任何字段 UnmarshalJSON strictly decodes the catalog union, requires every branch field of the selected layout, and rejects every field from the other layout
type CatalogItem ¶
type CatalogItem struct {
ResourceIndex int32 `json:"resourceIndex"` // ResourceFileNames 索引 / Index into ResourceFileNames
Name *string `json:"name"` // 资源名称 / Resource name
Hash uint64 `json:"hash"` // 资源哈希 / Resource hash
// contains filtered or unexported fields
}
CatalogItem 表示 C# AssetBundleCatalog.Item 的固定三槽资源索引条目 CatalogItem represents the fixed three-slot resource index entry from C# AssetBundleCatalog.Item
func (*CatalogItem) CodecDecodeSelf ¶
func (v *CatalogItem) CodecDecodeSelf(d *codec.Decoder)
CodecDecodeSelf 按固定三槽布局解码 CatalogItem CodecDecodeSelf decodes CatalogItem using its fixed three-slot layout
func (CatalogItem) CodecEncodeSelf ¶
func (v CatalogItem) CodecEncodeSelf(e *codec.Encoder)
CodecEncodeSelf 按固定三槽布局编码 CatalogItem CodecEncodeSelf encodes CatalogItem using its fixed three-slot layout
func (*CatalogItem) UnmarshalJSON ¶
func (value *CatalogItem) UnmarshalJSON(data []byte) error
UnmarshalJSON 严格解码 AssetBundle catalog 条目并要求三个字段显式出现 UnmarshalJSON strictly decodes an AssetBundle catalog item and requires all three fields to be explicitly present
type CatalogKind ¶
type CatalogKind string
CatalogKind 标识 KCES 使用的两种具体 catalog 布局 CatalogKind identifies the two concrete catalog layouts used by KCES
const ( CatalogKindAssetBundle CatalogKind = "assetBundle" CatalogKindVirtualAsset CatalogKind = "virtualAsset" )
type CatalogPackageType ¶
type CatalogPackageType int32
CatalogPackageType 是游戏 catalog 包类型枚举 CatalogPackageType is the game's catalog package-type enumeration
const ( PackageTypeBase CatalogPackageType = 0 PackageTypePlugin CatalogPackageType = 1 PackageTypePluginPatch CatalogPackageType = 2 PackageTypeBasePatch CatalogPackageType = 3 PackageTypeExtraBase CatalogPackageType = 4 PackageTypeExtraPatch CatalogPackageType = 5 )
type CatalogType ¶
type CatalogType int32
CatalogType 是游戏资源分类标志位枚举 CatalogType is the game's resource-category flag enumeration
const ( CatalogTypeUnknown CatalogType = 1 CatalogTypeLanguage CatalogType = 2 CatalogTypeProduct CatalogType = 4 CatalogTypeMovie CatalogType = 8 CatalogTypeScript CatalogType = 16 CatalogTypeSound CatalogType = 32 CatalogTypeVoice CatalogType = 64 CatalogTypeCsv CatalogType = 128 CatalogTypeSystem CatalogType = 256 CatalogTypeBg CatalogType = 512 CatalogTypeMotion CatalogType = 1024 CatalogTypePartsMeta CatalogType = 2048 CatalogTypeParts CatalogType = 4096 )
type ContentTable ¶
type ContentTable struct {
Version int32 `json:"Version"` // 保存的根 VirtualDirectory 版本 / Stored root VirtualDirectory version
Framing VirtualDirectoryFraming `json:"Framing,omitempty"` // MessagePack 目录的外层尾部封装 / Outer footer frame around the MessagePack directory
Directories map[string]VirtualDirectoryMetadata `json:"Directories,omitempty"` // 子目录路径及其真实版本字段,包含空目录 / Child-directory paths and their real version fields, including empty directories
Files map[string]VirtualFile `json:"Files"` // 虚拟文件表,键为文件名,值为位置和大小 / Virtual file table keyed by file name with position and size values
Raw []byte `json:"-"` // 完整文件原始字节,用于按偏移提取虚拟文件内容 / Raw bytes of the full file used to slice virtual file contents by offset
// contains filtered or unexported fields
}
ContentTable 表示解析后的 .ct 文件 VirtualDirectory 序列化结构 .ct 文件是 KCES 游戏的资源目录容器,内部存储 catalog、ExtensionNameList 等虚拟文件 游戏通过 CatalogUtility.FromCatalog<T> 读取 .ct 中的 "catalog" 文件获取资源索引 ContentTable represents a parsed .ct file in serialized VirtualDirectory form A .ct file is a KCES resource catalog container storing virtual files such as catalog and ExtensionNameList The game reads the "catalog" virtual file through CatalogUtility.FromCatalog<T> to obtain resource indexes
func NewContentTableFromDir ¶
func NewContentTableFromDir(dirPath string) (*ContentTable, error)
NewContentTableFromDir 从磁盘目录创建 ContentTable,将目录中所有文件作为虚拟文件 文件路径相对于 dirPath,并使用正斜杠分隔 NewContentTableFromDir creates a ContentTable from a disk directory and treats every file as a virtual file File paths are relative to dirPath and use slash separators
func ReadContentTable ¶
func ReadContentTable(r io.Reader) (*ContentTable, error)
ReadContentTable 从 reader 中读取并解析 .ct 文件 解析流程:验证签名、读取末尾长度、提取 MessagePack 数据、LZ4 解压并解码 VirtualDirectory ReadContentTable reads and parses a .ct file from reader The procedure validates the signature, reads the trailing length, extracts MessagePack data, decompresses LZ4, and decodes VirtualDirectory
func (*ContentTable) AddFile ¶
func (ct *ContentTable) AddFile(name string, data []byte) error
AddFile 向 ContentTable 追加一个虚拟文件 数据会追加到 Raw 的载荷区末尾,并自动更新 Position 和 Size AddFile appends a virtual file to ContentTable Data is appended to the end of the Raw payload area and Position and Size are updated automatically
func (*ContentTable) DecodeMsgpackFile ¶
func (ct *ContentTable) DecodeMsgpackFile(name string, out interface{}) error
DecodeMsgpackFile 提取虚拟文件并解码 MessagePack,同时自动处理 Lz4BlockArray 压缩 适用于读取 catalog、ExtensionNameList 等 MessagePack 序列化文件 DecodeMsgpackFile extracts a virtual file and decodes MessagePack while handling Lz4BlockArray compression automatically It is suitable for MessagePack files such as catalog and ExtensionNameList
func (*ContentTable) GetFileData ¶
func (ct *ContentTable) GetFileData(name string) ([]byte, error)
GetFileData 根据虚拟文件名提取原始字节数据 函数使用 Files 表中的 Position 和 Size 在 Raw 中切片返回 GetFileData extracts raw bytes for a virtual file name It slices Raw using Position and Size from the Files table
func (*ContentTable) GetFileNames ¶
func (ct *ContentTable) GetFileNames() []string
GetFileNames 返回按字典序排列的所有虚拟文件名 GetFileNames returns all virtual file names in lexicographic order
func (*ContentTable) GetVirtualDirectoryMetadata ¶
func (ct *ContentTable) GetVirtualDirectoryMetadata() map[string]VirtualDirectoryMetadata
GetVirtualDirectoryMetadata 返回子目录真实字段的深拷贝 GetVirtualDirectoryMetadata returns a deep copy of the real child-directory fields
type ExtensionNameList ¶
type ExtensionNameList struct {
Extension *string `json:"extention"` // 游戏字段名拼写为 extention,用途未知 / The game field is spelled extention and its purpose is unknown
Data []*ExtensionNamePack `json:"data"` // 名称和哈希条目 / Name and hash entries
// contains filtered or unexported fields
}
ExtensionNameList 表示 .ct 中按扩展名分组的资源名称列表 ExtensionNameList represents resource names grouped by extension in a .ct file
func DecodeExtensionNameList ¶
func DecodeExtensionNameList(data []byte) (*ExtensionNameList, error)
DecodeExtensionNameList 解码唯一完整的固定两槽 ExtensionNameList 根值 DecodeExtensionNameList decodes the sole complete fixed two-slot ExtensionNameList root
func DecodeExtensionNameListFromCt ¶
func DecodeExtensionNameListFromCt(table *ContentTable, extension string) (*ExtensionNameList, error)
DecodeExtensionNameListFromCt 从 .ct 中按扩展名读取并解码 ExtensionNameList DecodeExtensionNameListFromCt reads and decodes an ExtensionNameList from a .ct container by extension
func (*ExtensionNameList) CodecDecodeSelf ¶
func (v *ExtensionNameList) CodecDecodeSelf(d *codec.Decoder)
CodecDecodeSelf 按固定两槽布局解码 ExtensionNameList CodecDecodeSelf decodes ExtensionNameList using its fixed two-slot layout
func (ExtensionNameList) CodecEncodeSelf ¶
func (v ExtensionNameList) CodecEncodeSelf(e *codec.Encoder)
CodecEncodeSelf 按固定两槽布局编码 ExtensionNameList CodecEncodeSelf encodes ExtensionNameList using its fixed two-slot layout
func (*ExtensionNameList) UnmarshalJSON ¶
func (value *ExtensionNameList) UnmarshalJSON(data []byte) error
UnmarshalJSON 严格解码 ExtensionNameList 并要求扩展名与数据字段显式出现 UnmarshalJSON strictly decodes an ExtensionNameList and requires the extension and data fields to be explicitly present
type ExtensionNamePack ¶
type ExtensionNamePack struct {
Name *string `json:"name"` // 资源名称 / Resource name
Hash uint64 `json:"hash"` // 游戏字段用途未知 / The game field purpose is unknown
// contains filtered or unexported fields
}
ExtensionNamePack 表示 ExtensionNameList 中固定两槽的名称和哈希条目 ExtensionNamePack represents one fixed two-slot name and hash entry in ExtensionNameList
func (*ExtensionNamePack) CodecDecodeSelf ¶
func (v *ExtensionNamePack) CodecDecodeSelf(d *codec.Decoder)
CodecDecodeSelf 按固定两槽布局解码 ExtensionNamePack CodecDecodeSelf decodes ExtensionNamePack using its fixed two-slot layout
func (ExtensionNamePack) CodecEncodeSelf ¶
func (v ExtensionNamePack) CodecEncodeSelf(e *codec.Encoder)
CodecEncodeSelf 按固定两槽布局编码 ExtensionNamePack CodecEncodeSelf encodes ExtensionNamePack using its fixed two-slot layout
func (*ExtensionNamePack) UnmarshalJSON ¶
func (value *ExtensionNamePack) UnmarshalJSON(data []byte) error
UnmarshalJSON 严格解码 ExtensionNamePack 并要求名称与哈希字段显式出现 UnmarshalJSON strictly decodes an ExtensionNamePack and requires the name and hash fields to be explicitly present
type VirtualCatalogItem ¶
type VirtualCatalogItem struct {
AssetPath *string `json:"assetPath"` // Unity 工程资源路径 / Unity project asset path
Name *string `json:"name"` // 资源名称 / Resource name
Hash uint64 `json:"hash"` // 资源哈希 / Resource hash
// contains filtered or unexported fields
}
VirtualCatalogItem 表示 C# VirtualAssetCatalog.Item 的固定三槽本地资源条目 VirtualCatalogItem represents the fixed three-slot local-resource entry from C# VirtualAssetCatalog.Item
func (*VirtualCatalogItem) CodecDecodeSelf ¶
func (v *VirtualCatalogItem) CodecDecodeSelf(d *codec.Decoder)
CodecDecodeSelf 按固定三槽布局解码 VirtualCatalogItem CodecDecodeSelf decodes VirtualCatalogItem using its fixed three-slot layout
func (VirtualCatalogItem) CodecEncodeSelf ¶
func (v VirtualCatalogItem) CodecEncodeSelf(e *codec.Encoder)
CodecEncodeSelf 按固定三槽布局编码 VirtualCatalogItem CodecEncodeSelf encodes VirtualCatalogItem using its fixed three-slot layout
func (*VirtualCatalogItem) UnmarshalJSON ¶
func (value *VirtualCatalogItem) UnmarshalJSON(data []byte) error
UnmarshalJSON 严格解码 VirtualAsset catalog 条目并要求三个字段显式出现 UnmarshalJSON strictly decodes a VirtualAsset catalog item and requires all three fields to be explicitly present
type VirtualDirectoryFraming ¶
type VirtualDirectoryFraming uint8
VirtualDirectoryFraming 标识 MessagePack VirtualDirectory 元数据采用的外层尾部封装 / VirtualDirectoryFraming identifies the outer footer frame used around MessagePack VirtualDirectory metadata
const ( // VirtualDirectoryFramingLegacy 使用 0x8e 标记和四字节长度尾部 // VirtualDirectoryFramingLegacy uses marker 0x8e and a four-byte length footer VirtualDirectoryFramingLegacy VirtualDirectoryFraming = iota // VirtualDirectoryFramingExtended 使用 0xff 标记、八字节长度及固定签名尾部 // VirtualDirectoryFramingExtended uses marker 0xff, an eight-byte length, and a fixed footer signature VirtualDirectoryFramingExtended )
type VirtualDirectoryMetadata ¶
type VirtualDirectoryMetadata struct {
Version int32 `json:"Version"` // 子 VirtualDirectory 的版本值 / Child VirtualDirectory version value
}
VirtualDirectoryMetadata 保存子 VirtualDirectory 的真实字段 路径在 ContentTable.Directories 中以规范化的斜杠分隔键保存,解码得到的每个目录都会有条目 VirtualDirectoryMetadata stores the real fields of a child VirtualDirectory Paths use canonical slash-separated keys in ContentTable.Directories and every decoded directory has an entry
type VirtualFile ¶
type VirtualFile struct {
Position int64 `json:"Position"` // 文件数据在 .ct 文件中的绝对字节偏移,从文件开头计算且包含 header / Absolute byte offset of file data inside the .ct file, counted from file start including header
Size int32 `json:"Size"` // 文件数据的字节大小 / File data size in bytes
}
VirtualFile 表示虚拟文件系统中的一个文件条目 对应 C# VirtualFile 的 MessagePack indexed array [Key(0)=position, Key(1)=size] VirtualFile represents one file entry in the virtual file system It matches the C# VirtualFile MessagePack indexed array [Key(0)=position, Key(1)=size]