aba

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// 下列常量定义 FSHeader Flags 位
	// The following constants define FSHeader flag bits
	CompressionNone  = 0x00 // CompressionNone 表示不压缩 / CompressionNone denotes no compression
	CompressionLZMA  = 0x01 // CompressionLZMA 表示 LZMA 压缩 / CompressionLZMA denotes LZMA compression
	CompressionLZ4   = 0x02 // CompressionLZ4 表示 LZ4 压缩 / CompressionLZ4 denotes LZ4 compression
	CompressionLZ4HC = 0x03 // CompressionLZ4HC 表示高压缩率 LZ4HC 压缩 / / CompressionLZ4HC denotes higher-ratio LZ4HC compression
	CompressionMask  = 0x3f // CompressionMask 是低六位压缩类型掩码 / CompressionMask is the compression-type mask in the low six bits

	FlagHasDirectoryInfo            = 0x40  // FlagHasDirectoryInfo 表示块信息与目录信息组合保存 / FlagHasDirectoryInfo denotes combined block and directory information
	FlagBlockAndDirAtEnd            = 0x80  // FlagBlockAndDirAtEnd 表示 BlockAndDirInfo 位于文件末尾 / FlagBlockAndDirAtEnd denotes BlockAndDirInfo stored at file end
	FlagOldWebPluginCompat          = 0x100 // FlagOldWebPluginCompat 是旧版 Web 插件兼容位 / FlagOldWebPluginCompat is the old Web-plugin compatibility bit
	FlagBlockInfoNeedPaddingAtStart = 0x200 // FlagBlockInfoNeedPaddingAtStart 表示数据块起始需要 16 字节对齐 / FlagBlockInfoNeedPaddingAtStart denotes 16-byte alignment before data blocks

	// 下列常量定义 DirectoryInfo Flags 位
	// The following constants define DirectoryInfo flag bits
	DirFlagSerializedFile = 0x04 // DirFlagSerializedFile 表示条目是序列化 AssetsFile / DirFlagSerializedFile denotes a serialized AssetsFile entry

)
View Source
const (
	ClassIDGameObject    int32 = 1
	ClassIDTransform     int32 = 4
	ClassIDMaterial      int32 = 21
	ClassIDMeshRenderer  int32 = 23
	ClassIDTexture2D     int32 = 28
	ClassIDMeshFilter    int32 = 33
	ClassIDMesh          int32 = 43
	ClassIDShader        int32 = 48
	ClassIDTextAsset     int32 = 49
	ClassIDAnimationClip int32 = 74
	ClassIDAudioClip     int32 = 83
	ClassIDCubemap       int32 = 89
	ClassIDMonoBehaviour int32 = 114
	ClassIDMonoScript    int32 = 115
	ClassIDFont          int32 = 128
	ClassIDAssetBundle   int32 = 142
	ClassIDSprite        int32 = 213
	ClassIDSpriteAtlas   int32 = 687078895
)

下列常量是提取器识别的常用 Unity class ID The constants below are common Unity class IDs recognized by the extractors

View Source
const (
	TextureFormatAlpha8 int32 = 1
	TextureFormatRGB24  int32 = 3
	TextureFormatRGBA32 int32 = 4
	TextureFormatARGB32 int32 = 5
	TextureFormatDXT1   int32 = 10
	TextureFormatDXT5   int32 = 12
	TextureFormatBGRA32 int32 = 14
	TextureFormatBC6H   int32 = 24
	TextureFormatBC7    int32 = 25
	TextureFormatBC4    int32 = 26
	TextureFormatBC5    int32 = 27
	TextureFormatR8     int32 = 63
	TextureFormatRGBA64 int32 = 72
)
View Source
const AssetSceneExtension = ".asset_scene"
View Source
const MeshTexCoordSetCount = 8

MeshTexCoordSetCount 是 Unity Mesh 支持的纹理坐标组数量 MeshTexCoordSetCount is the number of texture-coordinate sets a Unity Mesh supports

View Source
const (
	// NativeUnityObjectFormatVersion 是独立 Unity 对象文件的当前格式版本
	// NativeUnityObjectFormatVersion is the current standalone Unity object file format version
	NativeUnityObjectFormatVersion uint32 = 1
)

Variables

This section is empty.

Functions

func DefaultAssetResolver

func DefaultAssetResolver(relativeTo *AssetsFile, fileID int32, pathID int64) (*AssetsFile, *AssetInfo, error)

DefaultAssetResolver 只解析同一 AssetsFile 内部引用 DefaultAssetResolver resolves references within the same AssetsFile only

func EncodeNativeUnityObject

func EncodeNativeUnityObject(object *NativeUnityObject) ([]byte, error)

EncodeNativeUnityObject 将独立 Unity 对象编码为字节切片 EncodeNativeUnityObject encodes a standalone Unity object into a byte slice

func FlipRGBA32Rows

func FlipRGBA32Rows(width int64, height int64, rgba []byte) []byte

FlipRGBA32Rows 在自上而下的图像行序与 Unity 自下而上的贴图行序之间垂直翻转 RGBA32 像素 该变换是自身的逆运算,因此图像转 Texture2D 与 Texture2D 转图像共用同一函数,尺寸与数据长度不一致时原样返回并交由编码器报告具体错误 FlipRGBA32Rows vertically flips RGBA32 pixels between top-down image row order and Unity's bottom-up texture row order The transform is its own inverse, so image-to-Texture2D and Texture2D-to-image conversion share this function; mismatched dimensions return the input unchanged and leave the encoder to report the exact error

func NativeUnityObjectSize

func NativeUnityObjectSize(object *NativeUnityObject) (int64, error)

NativeUnityObjectSize 校验独立对象并返回编码后的精确字节数 NativeUnityObjectSize validates a standalone object and returns its exact encoded byte size

func RewritePPtrReferences

func RewritePPtrReferences(root *TypeTreeValue, remap PPtrRemapFunc) (int64, error)

RewritePPtrReferences 遍历 TypeTree 值中的全部 PPtr 并原位重写非空引用 RewritePPtrReferences walks every PPtr in a TypeTree value and rewrites non-null references in place

func TextureDDSBytes

func TextureDDSBytes(tex *Texture2DData) ([]byte, error)

TextureDDSBytes 将 Texture2D 编码为可由常用图像工具读取的 DDS 字节 TextureDDSBytes encodes a Texture2D into DDS bytes readable by common image tools

func TexturePNGBytes

func TexturePNGBytes(tex *Texture2DData) ([]byte, error)

TexturePNGBytes 通过 ImageMagick 将 Unity Texture2D 载荷转换为 PNG 字节 TexturePNGBytes converts a Unity Texture2D payload to PNG bytes through ImageMagick

func WriteAba

func WriteAba(w io.Writer, entries []AbaFileEntry, opts *AbaWriteOptions) error

WriteAba 将文件条目列表写入采用 Unity AssetBundle UnityFS 格式的 .aba 文件 输出依次包含 Header、BlockAndDirInfo、16 字节对齐填充和数据块,数据块按 0x20000 字节分块并可选使用 LZ4 压缩 WriteAba writes file entries as an .aba file using the Unity AssetBundle UnityFS format Output contains Header, BlockAndDirInfo, 16-byte alignment padding, and data blocks in order; data is split into 0x20000-byte blocks with optional LZ4 compression

func WriteAnimationClip

func WriteAnimationClip(object *NativeUnityObject) ([]byte, error)

WriteAnimationClip 写入 ClassID 74 AnimationClip 独立对象文件 WriteAnimationClip writes a standalone ClassID 74 AnimationClip object file

func WriteAudioClip

func WriteAudioClip(object *NativeUnityObject) ([]byte, error)

WriteAudioClip 写入 ClassID 83 AudioClip 独立对象文件 WriteAudioClip writes a standalone ClassID 83 AudioClip object file

func WriteDDS

func WriteDDS(tex *Texture2DData, outPath string) error

WriteDDS 将原始 Unity 纹理载荷包裹 DDS 头后写入文件 WriteDDS writes the raw Unity texture payload wrapped in a DDS header

func WriteMMesh

func WriteMMesh(object *NativeUnityObject) ([]byte, error)

WriteMMesh 写入 ClassID 43 Mesh 独立对象文件 WriteMMesh writes a standalone ClassID 43 Mesh object file

func WriteMaterial

func WriteMaterial(object *NativeUnityObject) ([]byte, error)

WriteMaterial 写入 ClassID 21 Material 独立对象文件 WriteMaterial writes a standalone ClassID 21 Material object file

func WriteMonoBehaviour

func WriteMonoBehaviour(object *NativeUnityObject) ([]byte, error)

WriteMonoBehaviour 写入 ClassID 114 MonoBehaviour 独立对象文件 WriteMonoBehaviour writes a standalone ClassID 114 MonoBehaviour object file

func WriteNativeUnityObject

func WriteNativeUnityObject(out io.Writer, object *NativeUnityObject) error

WriteNativeUnityObject 写入带完整 TypeTree 和 Unity 对象正文的独立文件 WriteNativeUnityObject writes a standalone file containing a complete TypeTree and Unity object payload

func WritePartsAtlas

func WritePartsAtlas(object *NativeUnityObject) ([]byte, error)

WritePartsAtlas 写入 ClassID 687078895 SpriteAtlas 独立对象文件 WritePartsAtlas writes a standalone ClassID 687078895 SpriteAtlas object file

func WriteRawMagickInput

func WriteRawMagickInput(tex *Texture2DData, w io.Writer) error

WriteRawMagickInput 将供 ImageMagick 使用的原始输入字节写入目标,便于测试和调试 WriteRawMagickInput writes the raw bytes prepared for ImageMagick to a destination for tests and debugging

func WriteSpriteObject

func WriteSpriteObject(object *NativeUnityObject) ([]byte, error)

WriteSpriteObject 写入 ClassID 213 Sprite 独立对象文件 WriteSpriteObject writes a standalone ClassID 213 Sprite object file

func WriteSpritePNG

func WriteSpritePNG(sprite *SpriteExport, outPath string) error

WriteSpritePNG 将 Sprite 裁剪结果导出为 PNG 贴图解压和最终裁剪、翻转、旋转交给 ImageMagick 处理 WriteSpritePNG exports a Sprite crop as PNG Texture decompression and final crop, flip, and rotation are delegated to ImageMagick

func WriteSpritePNGTo

func WriteSpritePNGTo(sprite *SpriteExport, out io.Writer) error

WriteSpritePNGTo 将裁剪后的 Sprite PNG 写入已打开的目标,ImageMagick 输出到 stdout 以便调用方保留 os.Root 文件系统约束 WriteSpritePNGTo writes a cropped Sprite PNG to an open destination; ImageMagick emits to stdout so callers can retain filesystem confinement with an os.Root-backed handle

func WriteTexture2D

func WriteTexture2D(object *NativeUnityObject) ([]byte, error)

WriteTexture2D 写入 ClassID 28 Texture2D 独立对象文件 WriteTexture2D writes a standalone ClassID 28 Texture2D object file

func WriteTexturePNG

func WriteTexturePNG(tex *Texture2DData, outPath string) error

WriteTexturePNG 通过 ImageMagick 将 Unity Texture2D 载荷转换为 PNG 文件 WriteTexturePNG converts a Unity Texture2D payload to a PNG file through ImageMagick

func WriteTexturePNGTo

func WriteTexturePNGTo(tex *Texture2DData, out io.Writer) error

WriteTexturePNGTo 转换 Unity Texture2D 载荷并写入已打开的目标,ImageMagick 输出到 stdout 以便调用方使用受 os.Root 管理的文件 WriteTexturePNGTo converts a Unity Texture2D payload and writes the PNG to an open destination; keeping ImageMagick on stdout lets callers use os.Root-backed files without reopening a path in the external process

Types

type Aba

type Aba struct {
	Header     AbaHeader       // 文件头 / File header
	BlockInfo  BlockAndDirInfo // 压缩块和目录信息 / Compressed block and directory information
	DataReader io.ReadSeeker   // 压缩数据区 reader;各块按需解压 / Compressed data-area reader; blocks are decompressed on demand
	// contains filtered or unexported fields
}

Aba 表示一个采用 Unity AssetBundle UnityFS 格式的 .aba 文件 Aba represents one .aba file using the Unity AssetBundle UnityFS format

func ReadAba

func ReadAba(r io.ReadSeeker) (*Aba, error)

ReadAba 从 reader 的当前位置读取并解析采用 Unity AssetBundle UnityFS 格式的 .aba 文件 ReadAba reads and parses an .aba file in Unity AssetBundle UnityFS format from the reader's current position

func (*Aba) GetFileData

func (b *Aba) GetFileData(index int64) ([]byte, error)

GetFileData 读取指定目录索引的完整解压文件数据 GetFileData reads complete decompressed file data for a directory index

func (*Aba) GetFileDataByName

func (b *Aba) GetFileDataByName(name string) ([]byte, error)

GetFileDataByName 按目录条目名称读取完整解压文件数据 GetFileDataByName reads complete decompressed file data by directory-entry name

func (*Aba) GetFileDataRange

func (b *Aba) GetFileDataRange(index int64, offset int64, size int64) ([]byte, error)

GetFileDataRange 从目录索引指定的 .aba 条目读取字节范围,offset 和 size 相对于该目录条目 GetFileDataRange reads a byte range from an .aba entry selected by directory index, with offset and size relative to that entry

func (*Aba) GetFileDataRangeByName

func (b *Aba) GetFileDataRangeByName(name string, offset int64, size int64) ([]byte, error)

GetFileDataRangeByName 按名称读取 .aba 条目的字节范围,offset 和 size 相对于解压后的文件条目而非整个 UnityFS 数据流 GetFileDataRangeByName reads a byte range from a named .aba entry, with offset and size relative to the decompressed entry rather than the whole UnityFS data stream

func (*Aba) GetFileNames

func (b *Aba) GetFileNames() []string

GetFileNames 按目录表顺序返回 .aba 中所有文件名称 GetFileNames returns every file name in .aba directory-table order

type AbaEntryWriteFunc

type AbaEntryWriteFunc func(io.Writer) error

AbaEntryWriteFunc 将一个 ABA 目录条目的完整逻辑字节流写入目标 AbaEntryWriteFunc writes the complete logical byte stream of one ABA directory entry to a destination

type AbaFileEntry

type AbaFileEntry struct {
	Name         string            // 文件名,如 "CAB-xxx" / File name such as "CAB-xxx"
	Data         []byte            // 文件数据 / File data
	ReaderAt     io.ReaderAt       // 大型文件的范围读取源,与 Data 互斥 / Range-readable source for a large file, mutually exclusive with Data
	WriteTo      AbaEntryWriteFunc // 可重复调用的流式生成器,与 Data 和 ReaderAt 互斥 / Repeatable streaming generator, mutually exclusive with Data and ReaderAt
	Size         int64             // ReaderAt 或 WriteTo 提供的精确文件大小,使用 Data 时可为零 / Exact size supplied by ReaderAt or WriteTo, or zero when Data is used
	IsSerialized bool              // 是否为序列化 AssetsFile / Whether this entry is a serialized AssetsFile
}

AbaFileEntry 表示要写入 ABA 文件的一个目录条目 / AbaFileEntry represents one directory entry to write into an ABA file

type AbaFileRangeResolver

type AbaFileRangeResolver func(name string, offset int64, size int64) ([]byte, error)

AbaFileRangeResolver 解析非序列化 .aba 条目中的字节范围,Texture2D m_StreamData 通常指向大型 .resS sidecar,因此范围读取可避免每张贴图加载整文件 AbaFileRangeResolver resolves a byte range within a non-serialized .aba entry; Texture2D m_StreamData commonly points into a large .resS sidecar, so range reads avoid loading the whole file for every texture

type AbaFileResolver

type AbaFileResolver func(name string) ([]byte, error)

AbaFileResolver 解析同一 AssetBundle 内的非序列化文件,典型用途是读取 Texture2D 的 .resS 载荷 AbaFileResolver resolves non-serialized files in the same AssetBundle, typically Texture2D .resS payload data

type AbaHeader

type AbaHeader struct {
	Signature         string   // 签名,受支持的明文值为 "UnityFS" / Signature, with "UnityFS" as the supported plaintext value
	Version           uint32   // UnityFS 文件格式版本,当前支持 6 至 8 / UnityFS file-format version, currently supporting 6 through 8
	GenerationVersion string   // NUL 结尾的生成版本字符串,如 "5.x.x" / NUL-terminated generation-version string such as "5.x.x"
	EngineVersion     string   // NUL 结尾的 Unity 引擎版本字符串 / NUL-terminated Unity engine-version string
	FSHeader          FSHeader // 文件流头部 / File stream header
}

AbaHeader 表示 UnityFS 文件头,所有字段使用 Big-Endian 编码 AbaHeader represents the UnityFS header with Big-Endian fields

type AbaWriteOptions

type AbaWriteOptions struct {
	EngineVersion     string // Unity 引擎版本,默认固定为 2022.3.35f1 / Unity engine version, fixed to 2022.3.35f1 by default
	GenerationVersion string // 生成版本(如 "5.x.x"),默认 "5.x.x" / Generation version such as "5.x.x", default "5.x.x"
	Version           uint32 // 文件格式版本,默认 8 / File format version, default 8
	Compress          bool   // 是否使用 LZ4 压缩数据块 / Whether to compress data blocks with LZ4
}

AbaWriteOptions 控制 ABA 文件的写入行为 / AbaWriteOptions controls ABA file writing

type AnimationClipCurves

type AnimationClipCurves struct {
	Name   string              // Unity m_Name / Unity m_Name
	Curves []AnimationTRSCurve // 可导出的 TRS 曲线 / Exportable TRS curves
}

AnimationClipCurves 表示从 Unity AnimationClip 中提取的显式节点曲线 / AnimationClipCurves represents explicit node curves extracted from a Unity AnimationClip

type AnimationCurveProperty

type AnimationCurveProperty uint8

AnimationCurveProperty 表示可映射到 glTF 节点 TRS 的 Unity 曲线属性 / AnimationCurveProperty represents a Unity curve property that maps to glTF node TRS

const (
	// AnimationCurveTranslation 表示局部位置曲线 / AnimationCurveTranslation represents a local-position curve
	AnimationCurveTranslation AnimationCurveProperty = iota
	// AnimationCurveRotation 表示局部四元数旋转曲线 / AnimationCurveRotation represents a local quaternion-rotation curve
	AnimationCurveRotation
	// AnimationCurveScale 表示局部缩放曲线 / AnimationCurveScale represents a local-scale curve
	AnimationCurveScale
	// AnimationCurveEuler 表示需要转换为四元数的局部欧拉角曲线 / AnimationCurveEuler represents a local Euler-angle curve that requires quaternion conversion
	AnimationCurveEuler
)

type AnimationTRSCurve

type AnimationTRSCurve struct {
	Path      string                 // 相对于动画根节点的 Transform 路径 / Transform path relative to the animation root
	Property  AnimationCurveProperty // TRS 属性 / TRS property
	Dimension uint8                  // 值分量数量 / Value component count
	Keyframes []AnimationTRSKeyframe // 有序关键帧 / Ordered keyframes
}

AnimationTRSCurve 表示绑定到一个 Transform 路径的显式 TRS 曲线 / AnimationTRSCurve represents an explicit TRS curve bound to one Transform path

type AnimationTRSKeyframe

type AnimationTRSKeyframe struct {
	Time  float32    // 关键帧时间,单位为秒 / Keyframe time in seconds
	Value [4]float32 // XYZ 或 XYZW 值 / XYZ or XYZW value
}

AnimationTRSKeyframe 表示一个固定宽度的 Unity TRS 关键帧 / AnimationTRSKeyframe represents one fixed-width Unity TRS keyframe

type AssetBundleContainerEntry

type AssetBundleContainerEntry struct {
	Name         string // m_Container 键名或加载名 / m_Container key or load name
	PreloadIndex int32  // m_PreloadTable 起始索引 / Start index in m_PreloadTable
	PreloadSize  int32  // m_PreloadTable 引用数量 / Number of referenced preload entries
	FileID       int32  // PPtr 文件 ID,0 表示当前文件 / PPtr file ID, zero means current file
	PathID       int64  // PPtr 路径 ID / PPtr path ID
}

AssetBundleContainerEntry 表示 Unity AssetBundle 对象中的一个 m_Container 记录 Name 是 AssetBundle.LoadAsset 使用的键,可能与目标对象内部 m_Name 不同,尤其是原生对象 AssetBundleContainerEntry is one m_Container record from a Unity AssetBundle object Name is the key used by AssetBundle.LoadAsset and may differ from the target object's internal m_Name, especially for raw or native objects

type AssetEntry

type AssetEntry struct {
	PathId   int64  // SerializedFile 中唯一标识对象的路径 ID / Path ID identifying the object within the SerializedFile
	TypeId   int32  // 类型 ID / Unity class ID
	TypeName string // 内置映射得到的类型名称 / Type name obtained from the built-in mapping
	Name     string // 已知布局中位于开头的 m_Name,无法读取时为空 / Leading m_Name from known layouts, or empty when unavailable
	Size     uint32 // 序列化对象数据的字节数 / Serialized object data size in bytes
	Offset   int64  // 对象数据相对于 SerializedFile 数据区的偏移 / Object-data offset relative to the SerializedFile data section
}

AssetEntry 表示一个可提取的资源条目,包含名称、类型和数据范围信息 / AssetEntry represents one extractable asset entry with name, type, and data-range metadata

type AssetInfo

type AssetInfo struct {
	PathId          int64  // 文件内唯一标识资源的路径 ID / Asset PathID unique within the file
	ByteOffset      int64  // 相对于 DataOffset 的偏移 / Offset relative to DataOffset
	ByteSize        uint32 // 资源数据大小 / Asset data size
	TypeIdOrIndex   int32  // Serialized type 标识;v16+ 必须是 TypeTreeTypes 数组索引 / Serialized type identifier; v16+ must index TypeTreeTypes
	TypeId          int32  // 解析后填充的实际类型 ID / Actual class ID filled after parsing
	LegacyClassID   uint16 // v12 至 v15 对象项中显式保存的 class ID / Class ID stored explicitly in v12 through v15 object entries
	ScriptTypeIndex int16  // v12 至 v16 对象项中的脚本类型索引,-1 表示无脚本 / Script type index in v12 through v16 object entries, with -1 meaning no script
	Stripped        byte   // v15 至 v16 对象项中的 stripped 标记 / Stripped marker in v15 through v16 object entries
}

AssetInfo 表示单个序列化对象的元信息 / AssetInfo represents metadata for one serialized asset object

type AssetResolver

type AssetResolver func(relativeTo *AssetsFile, fileID int32, pathID int64) (*AssetsFile, *AssetInfo, error)

AssetResolver 解析 Unity PPtr 引用 fileID 0 表示当前 AssetsFile,正数 fileID 是从 1 开始的外部依赖索引 AssetResolver resolves Unity PPtr references fileID zero denotes the current AssetsFile, while positive file IDs are one-based external dependency indexes

func AbaAssetResolver

func AbaAssetResolver(files map[string]*AssetsFile) AssetResolver

AbaAssetResolver 返回可解析 .aba 内全部序列化文件的 resolver,映射键应包含 .aba 目录名或文件基名 AbaAssetResolver returns a resolver for all serialized files in an .aba; map keys should include .aba directory names or file basenames

type AssetsFile

type AssetsFile struct {
	Header   AssetsFileHeader // 文件头 / File header
	Metadata AssetsMetadata   // 包含类型树和资源列表的元数据 / Metadata including type trees and asset list
	Data     []byte           // 用于按偏移读取资源的原始文件数据 / Raw file bytes used to read assets by offset
	// contains filtered or unexported fields
}

AssetsFile 表示一个已解析的 Unity SerializedFile / AssetsFile represents one parsed Unity SerializedFile

func ReadAssetsFile

func ReadAssetsFile(data []byte) (*AssetsFile, error)

ReadAssetsFile 从字节数据中解析 Unity SerializedFile,并校验头部、metadata 边界和对象范围 ReadAssetsFile parses a Unity SerializedFile from bytes and validates its header, metadata bounds, and object ranges

func ReadAssetsFileRange

func ReadAssetsFileRange(fileSize int64, resolver AssetsFileRangeResolver) (*AssetsFile, error)

ReadAssetsFileRange 通过范围读取器解析 Unity SerializedFile,仅在访问对象时读取对象数据 ReadAssetsFileRange parses a Unity SerializedFile through a range reader and reads object data only when accessed

func (*AssetsFile) AssetHasTypeTree

func (af *AssetsFile) AssetHasTypeTree(info *AssetInfo) bool

AssetHasTypeTree 判断指定对象是否拥有可用于完整编解码的 TypeTree AssetHasTypeTree reports whether an object has a TypeTree capable of complete decoding and encoding

func (*AssetsFile) AssetTypeTree

func (af *AssetsFile) AssetTypeTree(info *AssetInfo) (TypeTreeType, error)

AssetTypeTree 返回指定对象使用的 TypeTree 深拷贝,使调用方可以安全地保存或修改独立对象布局 AssetTypeTree returns a deep copy of the TypeTree used by an object so callers can safely retain or modify a standalone layout

func (*AssetsFile) EncodeAssetValue

func (af *AssetsFile) EncodeAssetValue(info *AssetInfo, root *TypeTreeValue) ([]byte, error)

EncodeAssetValue 按资源对应的 TypeTree 和对象字节序重新编码已解码值 EncodeAssetValue re-encodes a decoded value using the asset TypeTree and object byte order

func (*AssetsFile) EncodeAssetValueAndTypeTreeForUnity2022

func (af *AssetsFile) EncodeAssetValueAndTypeTreeForUnity2022(info *AssetInfo, root *TypeTreeValue) ([]byte, TypeTreeType, bool, error)

EncodeAssetValueAndTypeTreeForUnity2022 将对象迁移到 Unity 2022.3,并同时返回与编码正文严格匹配的 TypeTree EncodeAssetValueAndTypeTreeForUnity2022 migrates an object to Unity 2022.3 and also returns the TypeTree that exactly matches the encoded payload

func (*AssetsFile) EncodeAssetValueForUnity2022

func (af *AssetsFile) EncodeAssetValueForUnity2022(info *AssetInfo, root *TypeTreeValue) ([]byte, bool, error)

EncodeAssetValueForUnity2022 将已解码对象迁移到 Unity 2022.3 内置类型布局并按对象字节序重新编码 EncodeAssetValueForUnity2022 migrates a decoded object to the Unity 2022.3 built-in type layout and re-encodes it using the object's byte order

func (*AssetsFile) GetAssetBundleContainerEntries

func (af *AssetsFile) GetAssetBundleContainerEntries(info *AssetInfo) ([]AssetBundleContainerEntry, error)

GetAssetBundleContainerEntries 解码 Unity AssetBundle 对象布局的稳定前缀 m_Name、m_PreloadTable 和 m_Container GetAssetBundleContainerEntries decodes the stable prefix of Unity's AssetBundle object layout containing m_Name, m_PreloadTable, and m_Container

func (*AssetsFile) GetAssetBundleContainerMap

func (af *AssetsFile) GetAssetBundleContainerMap() (map[int64]string, error)

GetAssetBundleContainerMap 返回从当前 AssetsFile 所有 Unity AssetBundle 对象收集的 PathID 到加载名映射 GetAssetBundleContainerMap returns a PathID-to-load-name map collected from all Unity AssetBundle objects in this AssetsFile

func (*AssetsFile) GetAssetData

func (af *AssetsFile) GetAssetData(info *AssetInfo) ([]byte, error)

GetAssetData 按 DataOffset、ByteOffset 和 ByteSize 提取指定资源的原始数据 GetAssetData extracts raw data for an asset using DataOffset, ByteOffset, and ByteSize

func (*AssetsFile) GetAssetEntries

func (af *AssetsFile) GetAssetEntries() []AssetEntry

GetAssetEntries 返回 AssetsFile 中全部对象的提取条目,并尝试读取已知布局的 m_Name GetAssetEntries returns extraction entries for every object in AssetsFile and attempts to read m_Name from known layouts

func (*AssetsFile) GetAssetInfoByPathID

func (af *AssetsFile) GetAssetInfoByPathID(pathID int64) *AssetInfo

GetAssetInfoByPathID 按 PathID 查找资源元信息 GetAssetInfoByPathID finds asset metadata by PathID

func (*AssetsFile) GetAssetsByType

func (af *AssetsFile) GetAssetsByType(typeId int32) []AssetInfo

GetAssetsByType 返回指定 Unity class ID 的所有资源元信息 GetAssetsByType returns metadata for all assets with the specified Unity class ID

func (*AssetsFile) GetSpriteExport

func (af *AssetsFile) GetSpriteExport(info *AssetInfo, resolver AssetResolver, streamResolver AbaFileResolver) (*SpriteExport, error)

GetSpriteExport 将 Unity Sprite 解析为 Texture2D、裁剪矩形和 SpriteSettings 支持直接 m_RD.texture 引用和通过 m_RenderDataMap 的 SpriteAtlas 间接引用 GetSpriteExport resolves a Unity Sprite to a Texture2D, crop rectangle, and SpriteSettings It supports direct m_RD.texture references and SpriteAtlas indirection through m_RenderDataMap

func (*AssetsFile) GetSpriteExportRange

func (af *AssetsFile) GetSpriteExportRange(info *AssetInfo, resolver AssetResolver, streamResolver AbaFileRangeResolver) (*SpriteExport, error)

GetSpriteExportRange 是 GetSpriteExport 的 sidecar 范围读取版本 GetSpriteExportRange is the sidecar range-read variant of GetSpriteExport

func (*AssetsFile) GetTextAssetData

func (af *AssetsFile) GetTextAssetData(info *AssetInfo) (name string, script []byte, err error)

GetTextAssetData 提取 TextAsset 的 m_Name 和 m_Script 字节数组 当前支持的对象布局依次为 m_Name 对齐字符串和 m_Script 字节数组 GetTextAssetData extracts the m_Name and m_Script byte array from a TextAsset The supported object layout contains an aligned m_Name string followed by the m_Script byte array

func (*AssetsFile) GetTexture2DData

func (af *AssetsFile) GetTexture2DData(info *AssetInfo, resolver AbaFileResolver) (*Texture2DData, error)

GetTexture2DData 解码 Texture2D 元数据并返回原始编码图像数据,m_StreamData 中的外部数据通过 resolver 读取 GetTexture2DData decodes Texture2D metadata and returns raw encoded image data, resolving external m_StreamData through resolver

func (*AssetsFile) GetTexture2DDataRange

func (af *AssetsFile) GetTexture2DDataRange(info *AssetInfo, resolver AbaFileRangeResolver) (*Texture2DData, error)

GetTexture2DDataRange 是 GetTexture2DData 的范围读取版本 GetTexture2DDataRange is the range-read variant of GetTexture2DData

func (*AssetsFile) InlineAudioClipStreamData

func (af *AssetsFile) InlineAudioClipStreamData(info *AssetInfo, resolver AbaFileRangeResolver) ([]byte, bool, error)

InlineAudioClipStreamData 将 AudioClip 的外部 m_Resource 载荷改为对象字段后的内联音频数据 InlineAudioClipStreamData converts an external AudioClip m_Resource payload into audio bytes appended after the serialized object fields

func (*AssetsFile) InlineCubemapStreamData

func (af *AssetsFile) InlineCubemapStreamData(info *AssetInfo, resolver AbaFileRangeResolver) ([]byte, bool, error)

InlineCubemapStreamData 将 Cubemap 的外部流式载荷写回 image data 并清空 m_StreamData InlineCubemapStreamData writes a Cubemap external stream payload back into image data and clears m_StreamData

func (*AssetsFile) InlineMeshStreamData

func (af *AssetsFile) InlineMeshStreamData(info *AssetInfo, resolver AbaFileRangeResolver) ([]byte, bool, error)

InlineMeshStreamData 将 Mesh 的外部顶点载荷写回 m_VertexData.m_DataSize 并清空 m_StreamData InlineMeshStreamData writes an external Mesh vertex payload back into m_VertexData.m_DataSize and clears m_StreamData

func (*AssetsFile) InlineTexture2DStreamData

func (af *AssetsFile) InlineTexture2DStreamData(info *AssetInfo, resolver AbaFileRangeResolver) ([]byte, bool, error)

InlineTexture2DStreamData 将 Texture2D 的外部流式载荷写回 image data 并清空 m_StreamData InlineTexture2DStreamData writes a Texture2D external stream payload back into image data and clears m_StreamData

func (*AssetsFile) ReadAssetValue

func (af *AssetsFile) ReadAssetValue(info *AssetInfo) (*TypeTreeValue, error)

ReadAssetValue 使用资源的 TypeTree 解码对象,并确认类型树和对象数据均被完整消费 ReadAssetValue decodes an asset object with its TypeTree and verifies that both the tree and object data are fully consumed

type AssetsFileHeader

type AssetsFileHeader struct {
	MetadataSize       uint32  // 元数据块大小 / Metadata block size
	FileSize           int64   // 整个文件大小 / Total file size
	Version            uint32  // 序列化格式版本,当前支持 12 至 22 / Serialized file format version, currently supporting 12 through 22
	DataOffset         int64   // 资源数据区起始偏移 / Start offset of the asset data area
	Endianness         bool    // true 表示 Big-Endian,false 表示 Little-Endian / true means Big-Endian and false means Little-Endian
	LegacyMetadataSize uint32  // 固定头部中的 32 位元数据大小,v22 起通常为零并由扩展头替代 / 32-bit metadata size in the fixed header, normally zero and superseded by the extended header from v22
	LegacyFileSize     uint32  // 固定头部中的 32 位文件大小,v22 起通常为零并由扩展头替代 / 32-bit file size in the fixed header, normally zero and superseded by the extended header from v22
	LegacyDataOffset   uint32  // 固定头部中的 32 位数据偏移,v22 起通常为零并由扩展头替代 / 32-bit data offset in the fixed header, normally zero and superseded by the extended header from v22
	Reserved           [3]byte // Endianness 后由 Unity 读取并跳过的三个保留字节 / Three reserved bytes Unity reads and skips after Endianness
	LargeFilesUnknown  int64   // v22 扩展头末尾用途未知的 Int64 字段 / Int64 field of unknown purpose at the end of the v22 extended header
}

AssetsFileHeader 表示 Unity 序列化文件头 / AssetsFileHeader represents a Unity serialized file header

type AssetsFileRangeResolver

type AssetsFileRangeResolver func(offset int64, size int64) ([]byte, error)

AssetsFileRangeResolver 从 SerializedFile 的绝对偏移读取精确字节范围 AssetsFileRangeResolver reads an exact byte range at an absolute SerializedFile offset

type AssetsMetadata

type AssetsMetadata struct {
	UnityVersion    string                            // Unity 版本字符串 / Unity version string
	TargetPlatform  uint32                            // 目标平台 ID / Target platform ID
	TypeTreeEnabled bool                              // 是否包含类型树 / Whether type tree data is present
	TypeTreeTypes   []TypeTreeType                    // 类型树定义列表 / Type tree definition list
	BigIDEnabled    int32                             // v7-v13 的 64 位 PathID 开关;保留原始 int32 wire 值 / v7-v13 64-bit PathID switch; preserves the original int32 wire value
	AssetInfos      []AssetInfo                       // 资源信息列表 / Asset metadata list
	ScriptTypes     []LocalSerializedObjectIdentifier // 本地脚本对象引用 / Local script object identifiers
	ExternalFiles   []ExternalFile                    // 外部文件引用 / External file references
	RefTypes        []TypeTreeType                    // 引用类型定义 / Referenced serialized type definitions
	UserInformation string                            // metadata 尾部用户信息 / User-information string at the metadata tail
}

AssetsMetadata 包含类型树、资源信息和 metadata 尾部 / AssetsMetadata contains type trees, asset metadata, and the metadata tail

type BlockAndDirInfo

type BlockAndDirInfo struct {
	Hash           [16]byte        // 16 字节哈希 / 16-byte hash
	BlockInfos     []BlockInfo     // 数据压缩块信息列表 / Data block info list
	DirectoryInfos []DirectoryInfo // 文件目录条目列表 / File directory entry list
}

BlockAndDirInfo 包含数据块列表和文件目录列表 BlockAndDirInfo contains the data-block and directory lists

type BlockInfo

type BlockInfo struct {
	DecompressedSize uint32 // 解压后大小 / Decompressed size
	CompressedSize   uint32 // 压缩后大小,未压缩时与 DecompressedSize 相同 / Compressed size, equal to DecompressedSize when uncompressed
	Flags            uint16 // 标志位:低 6 位为压缩类型,bit6 表示是否为流式块 / Flags, low 6 bits are compression type and bit6 marks streamed blocks
}

BlockInfo 描述一个数据压缩块的元信息 BlockInfo describes one compressed data block

func (*BlockInfo) GetCompressionType

func (b *BlockInfo) GetCompressionType() byte

GetCompressionType 返回数据块 Flags 低六位中的压缩类型 GetCompressionType returns the compression type from the low six bits of data-block Flags

type DirectoryInfo

type DirectoryInfo struct {
	Offset           int64  // 相对于数据区起始的偏移量 / Offset relative to the data area start
	DecompressedSize int64  // 解压后大小 / Decompressed size
	Flags            uint32 // 目录条目标志,0x04 表示序列化 AssetsFile / Directory-entry flags, with 0x04 denoting a serialized AssetsFile
	Name             string // 文件名 / File name
}

DirectoryInfo 描述 .aba 文件内的一个目录条目 DirectoryInfo describes one directory entry inside an .aba file

func (*DirectoryInfo) IsSerialized

func (d *DirectoryInfo) IsSerialized() bool

IsSerialized 返回目录条目是否标记为序列化 AssetsFile IsSerialized reports whether the directory entry is marked as a serialized AssetsFile

type ExternalFile

type ExternalFile struct {
	AssetPath string   // 缓存资源虚拟路径 / Virtual cached-asset path
	Guid      [16]byte // 外部文件 GUID / External file GUID
	Type      int32    // 引用类型 / Reference type
	PathName  string   // 路径名 / Path name
}

ExternalFile 表示 SerializedFile 的外部文件引用 / ExternalFile represents an external file reference from a SerializedFile

type FSHeader

type FSHeader struct {
	TotalFileSize    int64  // 整个文件的总大小 / Total file size
	CompressedSize   uint32 // BlockAndDirInfo 压缩后的字节大小 / Compressed size of BlockAndDirInfo
	DecompressedSize uint32 // BlockAndDirInfo 解压后的字节大小 / Decompressed size of BlockAndDirInfo
	Flags            uint32 // 组合压缩类型与布局位的标志 / Flags combining compression type and layout bits
}

FSHeader 表示紧跟在 AbaHeader 字符串字段之后的 UnityFS 文件流头部 FSHeader represents UnityFS stream header fields following the AbaHeader strings

func (*FSHeader) GetCompressionType

func (h *FSHeader) GetCompressionType() byte

GetCompressionType 返回 FSHeader Flags 低六位中的块目录元数据压缩类型 GetCompressionType returns the block-directory metadata compression type from the low six bits of FSHeader Flags

type LocalSerializedObjectIdentifier

type LocalSerializedObjectIdentifier struct {
	LocalSerializedFileIndex int32 // 本地序列化文件索引 / Local serialized-file index
	LocalIdentifierInFile    int64 // 文件内对象 ID / Local object identifier in the file
}

LocalSerializedObjectIdentifier 标识 metadata 中的本地脚本对象 / LocalSerializedObjectIdentifier identifies a local script object in metadata

type MeshGeometry

type MeshGeometry struct {
	Name         string                             // Unity m_Name / Unity m_Name
	Positions    [][3]float32                       // 顶点位置 / Vertex positions
	Normals      [][3]float32                       // 可选顶点法线 / Optional vertex normals
	Tangents     [][4]float32                       // 可选顶点切线 / Optional vertex tangents
	Colors       [][4]float32                       // 可选顶点颜色 / Optional vertex colors
	TexCoords    [MeshTexCoordSetCount][][2]float32 // 可选纹理坐标组,索引即 UV 组序号 / Optional texture-coordinate sets indexed by UV set number
	SkinCounts   []uint8                            // 每顶点骨骼影响数量,未蒙皮时为 nil / Bone influence count per vertex, nil when unskinned
	SkinIndices  []uint32                           // 按顶点顺序扁平化的骨骼索引 / Bone indices flattened in vertex order
	SkinWeights  []float32                          // 按顶点顺序扁平化的骨骼权重 / Bone weights flattened in vertex order
	BindPoses    [][16]float32                      // 可选骨骼绑定姿势矩阵,按 e00 到 e33 的行主序 / Optional bone bind-pose matrices in row-major e00 through e33 order
	MorphTargets []MeshMorphTarget                  // 可选内嵌 BlendShape 目标 / Optional embedded blend-shape targets
	Primitives   []MeshPrimitive                    // SubMesh 图元 / SubMesh primitives
}

MeshGeometry 表示从 Unity Mesh 中解码的通用几何数据 / MeshGeometry represents generic geometry decoded from a Unity Mesh

type MeshMorphTarget

type MeshMorphTarget struct {
	Name           string       // BlendShape 名称 / Blend-shape name
	FrameWeight    float32      // 帧权重,通常为一百 / Frame weight, normally one hundred
	DeltaPositions [][3]float32 // 顶点位置差分,长度等于顶点数 / Vertex position deltas with one entry per vertex
	DeltaNormals   [][3]float32 // 可选法线差分 / Optional normal deltas
	DeltaTangents  [][3]float32 // 可选切线差分 / Optional tangent deltas
}

MeshMorphTarget 表示 Unity Mesh 内嵌的一个单帧 BlendShape / MeshMorphTarget represents one single-frame blend shape embedded in a Unity Mesh

type MeshPrimitive

type MeshPrimitive struct {
	Mode    MeshPrimitiveMode // 图元拓扑 / Primitive topology
	Indices []uint32          // 已应用 baseVertex 的顶点索引 / Vertex indices with baseVertex applied
}

MeshPrimitive 表示一个已展开为通用索引拓扑的 Unity SubMesh / MeshPrimitive represents one Unity SubMesh expanded to generic indexed topology

type MeshPrimitiveMode

type MeshPrimitiveMode uint8

MeshPrimitiveMode 表示可直接映射到 glTF 的网格图元拓扑 / MeshPrimitiveMode represents mesh primitive topology that maps directly to glTF

const (
	// MeshPrimitiveModePoints 表示独立点图元 / MeshPrimitiveModePoints represents independent point primitives
	MeshPrimitiveModePoints MeshPrimitiveMode = 0
	// MeshPrimitiveModeLines 表示独立线段图元 / MeshPrimitiveModeLines represents independent line primitives
	MeshPrimitiveModeLines MeshPrimitiveMode = 1
	// MeshPrimitiveModeLineStrip 表示连续线带图元 / MeshPrimitiveModeLineStrip represents a connected line-strip primitive
	MeshPrimitiveModeLineStrip MeshPrimitiveMode = 3
	// MeshPrimitiveModeTriangles 表示独立三角形图元 / MeshPrimitiveModeTriangles represents independent triangle primitives
	MeshPrimitiveModeTriangles MeshPrimitiveMode = 4
)

type NativeUnityObject

type NativeUnityObject struct {
	ClassID   int32        // Unity ClassID / Unity ClassID
	BigEndian bool         // 对象正文是否使用大端字节序 / Whether the object payload uses big-endian byte order
	TypeTree  TypeTreeType // 解码和重编码正文所需的完整 TypeTree / Complete TypeTree required to decode and re-encode the payload
	Data      []byte       // Unity 序列化对象正文 / Unity serialized object payload
}

NativeUnityObject 表示无需 sidecar 即可解析和重编码的独立 Unity 对象 / NativeUnityObject represents a standalone Unity object that can be decoded and re-encoded without sidecars

func NewNativeMeshObject

func NewNativeMeshObject(name string, geometry *MeshGeometry) (*NativeUnityObject, error)

NewNativeMeshObject 从通用几何数据构建携带官方 Unity 2022.3 TypeTree 的独立 Mesh 对象 顶点布局与官方网格一致,位置、法线、切线和颜色在流零,纹理坐标在下一个流,蒙皮通道在最后一个流 NewNativeMeshObject builds a standalone Mesh object carrying the official Unity 2022.3 TypeTree from generic geometry The vertex layout matches official meshes, with position, normal, tangent, and color in stream zero, texture coordinates in the next stream, and skin channels in the last stream

func NewNativeTexture2DObject

func NewNativeTexture2DObject(name string, width int64, height int64, rgba []byte) (*NativeUnityObject, error)

NewNativeTexture2DObject 从自上而下的 RGBA32 像素构建自带 Unity 2022.3 内置 TypeTree 的独立 Texture2D 对象,图像数据翻转为 Unity 自下而上行序后内联为单 mip RGBA32 NewNativeTexture2DObject builds a standalone Texture2D object carrying the Unity 2022.3 built-in TypeTree from top-down RGBA32 pixels, inlining the image data as a single RGBA32 mip after flipping it into Unity's bottom-up row order

func ReadAnimationClip

func ReadAnimationClip(data []byte) (*NativeUnityObject, error)

ReadAnimationClip 读取 ClassID 74 AnimationClip 独立对象文件 ReadAnimationClip reads a standalone ClassID 74 AnimationClip object file

func ReadAudioClip

func ReadAudioClip(data []byte) (*NativeUnityObject, error)

ReadAudioClip 读取 ClassID 83 AudioClip 独立对象文件 ReadAudioClip reads a standalone ClassID 83 AudioClip object file

func ReadMMesh

func ReadMMesh(data []byte) (*NativeUnityObject, error)

ReadMMesh 读取 ClassID 43 Mesh 独立对象文件 ReadMMesh reads a standalone ClassID 43 Mesh object file

func ReadMaterial

func ReadMaterial(data []byte) (*NativeUnityObject, error)

ReadMaterial 读取 ClassID 21 Material 独立对象文件 ReadMaterial reads a standalone ClassID 21 Material object file

func ReadMonoBehaviour

func ReadMonoBehaviour(data []byte) (*NativeUnityObject, error)

ReadMonoBehaviour 读取 ClassID 114 MonoBehaviour 独立对象文件 ReadMonoBehaviour reads a standalone ClassID 114 MonoBehaviour object file

func ReadNativeUnityObject

func ReadNativeUnityObject(data []byte) (*NativeUnityObject, error)

ReadNativeUnityObject 读取包含完整 TypeTree 和正文的独立 Unity 对象字节 ReadNativeUnityObject reads standalone Unity object bytes containing a complete TypeTree and payload

func ReadPartsAtlas

func ReadPartsAtlas(data []byte) (*NativeUnityObject, error)

ReadPartsAtlas 读取 ClassID 687078895 SpriteAtlas 独立对象文件 ReadPartsAtlas reads a standalone ClassID 687078895 SpriteAtlas object file

func ReadSpriteObject

func ReadSpriteObject(data []byte) (*NativeUnityObject, error)

ReadSpriteObject 读取 ClassID 213 Sprite 独立对象文件 ReadSpriteObject reads a standalone ClassID 213 Sprite object file

func ReadTexture2D

func ReadTexture2D(data []byte) (*NativeUnityObject, error)

ReadTexture2D 读取 ClassID 28 Texture2D 独立对象文件 ReadTexture2D reads a standalone ClassID 28 Texture2D object file

func (*NativeUnityObject) AssetsFileView

func (object *NativeUnityObject) AssetsFileView() (*AssetsFile, *AssetInfo, error)

AssetsFileView 返回仅用于现有 Unity 对象提取器的单对象 SerializedFile 视图 AssetsFileView returns a one-object SerializedFile view intended for existing Unity object extractors

func (*NativeUnityObject) AudioData

func (object *NativeUnityObject) AudioData() ([]byte, error)

AudioData 返回 AudioClip 的实际内联音频载荷,不包含尾部对齐填充 AudioData returns an AudioClip's actual inline audio payload without trailing alignment padding

func (*NativeUnityObject) DecodeAnimationClipCurves

func (object *NativeUnityObject) DecodeAnimationClipCurves() (*AnimationClipCurves, error)

DecodeAnimationClipCurves 使用内嵌 TypeTree 提取带明文 Transform 路径的显式 TRS 曲线 DecodeAnimationClipCurves extracts explicit TRS curves with clear-text Transform paths using the embedded TypeTree

func (*NativeUnityObject) DecodeMeshGeometry

func (object *NativeUnityObject) DecodeMeshGeometry() (*MeshGeometry, error)

DecodeMeshGeometry 使用独立对象内嵌 TypeTree 解码 Unity 2019 及更高版本的 Mesh 顶点和 SubMesh 数据 DecodeMeshGeometry decodes Unity 2019 and newer Mesh vertex and SubMesh data using the standalone object's embedded TypeTree

func (*NativeUnityObject) DecodeValue

func (object *NativeUnityObject) DecodeValue() (*TypeTreeValue, error)

DecodeValue 使用文件自带的 TypeTree 解码 Unity 对象正文 DecodeValue decodes the Unity object payload using the TypeTree embedded in the file

func (*NativeUnityObject) DecodeValueAndTrailingData

func (object *NativeUnityObject) DecodeValueAndTrailingData() (*TypeTreeValue, []byte, error)

DecodeValueAndTrailingData 使用文件自带的 TypeTree 解码对象字段,并返回 AudioClip 的内联尾随载荷 DecodeValueAndTrailingData decodes object fields using the embedded TypeTree and returns an AudioClip's inline trailing payload

func (*NativeUnityObject) EncodeValue

func (object *NativeUnityObject) EncodeValue(root *TypeTreeValue) ([]byte, error)

EncodeValue 使用文件自带的 TypeTree 重编码一个已修改的值树 EncodeValue re-encodes a modified value tree using the TypeTree embedded in the file

func (*NativeUnityObject) EncodeValueWithTrailingData

func (object *NativeUnityObject) EncodeValueWithTrailingData(root *TypeTreeValue, trailing []byte) ([]byte, error)

EncodeValueWithTrailingData 使用文件自带的 TypeTree 重编码字段,并为 AudioClip 追加经过校验的内联载荷 EncodeValueWithTrailingData re-encodes fields using the embedded TypeTree and appends validated inline payload data for an AudioClip

type NativeUnityObjectHeader

type NativeUnityObjectHeader struct {
	ClassID    int32        // Unity ClassID / Unity ClassID
	BigEndian  bool         // 对象正文是否使用大端字节序 / Whether the object payload uses big-endian byte order
	TypeTree   TypeTreeType // 解码和重编码正文所需的完整 TypeTree / Complete TypeTree required to decode and re-encode the payload
	DataOffset int64        // 对象正文相对于文件开头的偏移 / Object payload offset relative to the beginning of the file
	DataSize   uint32       // 对象正文在线格式字节数 / Object payload byte size on the wire
}

NativeUnityObjectHeader 描述独立 Unity 对象文件中自带的 ClassID、TypeTree 和正文范围 / NativeUnityObjectHeader describes the embedded ClassID, TypeTree, and payload range of a standalone Unity object file

func ReadNativeUnityObjectHeader

func ReadNativeUnityObjectHeader(in io.Reader, fileSize int64) (*NativeUnityObjectHeader, error)

ReadNativeUnityObjectHeader 读取并校验独立 Unity 对象头与 TypeTree,读取结束后 reader 位于正文开头 ReadNativeUnityObjectHeader reads and validates a standalone Unity object header and TypeTree and leaves the reader at the payload start

type PPtrRemapFunc

type PPtrRemapFunc func(fileID int32, pathID int64) (newFileID int32, newPathID int64, err error)

PPtrRemapFunc 将一个 Unity PPtr 的文件 ID 和路径 ID 映射为新的目标 PPtrRemapFunc maps one Unity PPtr file ID and path ID to a new target

type SerializedFileWriter

type SerializedFileWriter struct {
	UnityVersion    string // Unity 版本字符串,默认固定为 2022.3.35f1 / Unity version string, fixed to 2022.3.35f1 by default
	TargetPlatform  uint32 // 目标平台 ID,19 表示 Windows Standalone 64 位 / Target platform ID, with 19 meaning 64-bit Windows Standalone
	AssetBundleName string // 写入容器对象 m_AssetBundleName 的包名,官方文件形如 name.aba / Bundle name written to the container's m_AssetBundleName, shaped like name.aba in official files
	// contains filtered or unexported fields
}

SerializedFileWriter 生成包含 TextAsset、Texture2D、原始对象和 AssetBundle 容器的 Unity SerializedFile v22 / SerializedFileWriter generates Unity SerializedFile v22 data containing TextAsset, Texture2D, raw objects, and an AssetBundle container

func NewSerializedFileWriter

func NewSerializedFileWriter(unityVersion string) *SerializedFileWriter

NewSerializedFileWriter 创建一个新的 SerializedFile v22 写入器并验证 Unity 版本 NewSerializedFileWriter creates a new SerializedFile v22 writer and validates the Unity version

func (*SerializedFileWriter) AddNativeUnityObjectSourceWithLoadNameAndPathID

func (w *SerializedFileWriter) AddNativeUnityObjectSourceWithLoadNameAndPathID(classID int32, tree TypeTreeType, name string, loadName string, source SerializedObjectDataSource, pathID int64) int64

AddNativeUnityObjectSourceWithLoadNameAndPathID 添加可流式读取正文且携带完整 TypeTree 的独立 Unity 对象 AddNativeUnityObjectSourceWithLoadNameAndPathID adds a standalone Unity object with streamed payload data and a complete TypeTree

func (*SerializedFileWriter) AddNativeUnityObjectWithLoadNameAndPathID

func (w *SerializedFileWriter) AddNativeUnityObjectWithLoadNameAndPathID(object *NativeUnityObject, name string, loadName string, pathID int64) int64

AddNativeUnityObjectWithLoadNameAndPathID 添加携带完整 TypeTree 的独立 Unity 对象,并仅把其正文写入 SerializedFile AddNativeUnityObjectWithLoadNameAndPathID adds a standalone Unity object with a complete TypeTree and writes only its payload into the SerializedFile

func (*SerializedFileWriter) AddRawObject

func (w *SerializedFileWriter) AddRawObject(classId int32, name string, data []byte) int64

AddRawObject 添加一个原始数据对象,如 Mesh,并返回分配的 PathID AddRawObject adds a raw data object such as Mesh and returns the allocated PathID

func (*SerializedFileWriter) AddRawObjectPreservingDataWithLoadNameAndPathID

func (w *SerializedFileWriter) AddRawObjectPreservingDataWithLoadNameAndPathID(classId int32, name string, loadName string, data []byte, pathID int64) int64

AddRawObjectPreservingDataWithLoadNameAndPathID 添加原始 Unity 对象并严格保留对象数据字节,仅使用 name 和 loadName 构建索引 AddRawObjectPreservingDataWithLoadNameAndPathID adds a raw Unity object while preserving its data bytes exactly and uses name and loadName only for indexing

func (*SerializedFileWriter) AddRawObjectSourcePreservingDataWithLoadNameAndPathID

func (w *SerializedFileWriter) AddRawObjectSourcePreservingDataWithLoadNameAndPathID(classId int32, name string, loadName string, source SerializedObjectDataSource, pathID int64) int64

AddRawObjectSourcePreservingDataWithLoadNameAndPathID 添加流式原始 Unity 对象并严格保留其数据字节 AddRawObjectSourcePreservingDataWithLoadNameAndPathID adds a streamed raw Unity object while preserving its data bytes exactly

func (*SerializedFileWriter) AddRawObjectWithLoadName

func (w *SerializedFileWriter) AddRawObjectWithLoadName(classId int32, name string, loadName string, data []byte) int64

AddRawObjectWithLoadName 添加内部 m_Name 可不同于 AssetBundle m_Container LoadAsset 键的原始 Unity 对象 AddRawObjectWithLoadName adds a raw serialized Unity object whose internal m_Name can differ from the AssetBundle m_Container key used by LoadAsset

func (*SerializedFileWriter) AddRawObjectWithLoadNameAndPathID

func (w *SerializedFileWriter) AddRawObjectWithLoadNameAndPathID(classId int32, name string, loadName string, data []byte, pathID int64) int64

AddRawObjectWithLoadNameAndPathID 添加带独立 m_Name、AssetBundle 加载键和首选 PathID 的原始 Unity 对象 AddRawObjectWithLoadNameAndPathID adds a raw serialized Unity object with separate internal m_Name, AssetBundle load key, and preferred PathID

func (*SerializedFileWriter) AddRawObjectWithPathID

func (w *SerializedFileWriter) AddRawObjectWithPathID(classId int32, name string, data []byte, pathID int64) int64

AddRawObjectWithPathID 使用首选 PathID 添加原始 Unity 序列化对象 如果请求的 PathID 为零或已占用,会重新分配以保持 SerializedFile 有效 AddRawObjectWithPathID adds a raw serialized Unity object with a preferred PathID If the requested PathID is zero or already used, a fresh PathID is allocated to keep the SerializedFile valid

func (*SerializedFileWriter) AddTextAsset

func (w *SerializedFileWriter) AddTextAsset(name string, script []byte) int64

AddTextAsset 添加一个 TextAsset 对象,name 是资源名称,script 是 m_Script 数据 返回分配的 PathID AddTextAsset adds a TextAsset whose name is the resource name and whose script is m_Script data It returns the allocated PathID

func (*SerializedFileWriter) AddTextAssetWithLoadName

func (w *SerializedFileWriter) AddTextAssetWithLoadName(name string, loadName string, script []byte) int64

AddTextAssetWithLoadName 添加内部 m_Name 可不同于 AssetBundle m_Container LoadAsset 键的 TextAsset AddTextAssetWithLoadName adds a TextAsset whose internal m_Name can differ from the AssetBundle m_Container key used by LoadAsset

func (*SerializedFileWriter) AddTextAssetWithLoadNameAndPathID

func (w *SerializedFileWriter) AddTextAssetWithLoadNameAndPathID(name string, loadName string, script []byte, pathID int64) int64

AddTextAssetWithLoadNameAndPathID 添加带独立 m_Name、AssetBundle 加载键和首选 PathID 的 TextAsset AddTextAssetWithLoadNameAndPathID adds a TextAsset with separate internal m_Name, AssetBundle load key, and preferred PathID

func (*SerializedFileWriter) AddTextAssetWithPathID

func (w *SerializedFileWriter) AddTextAssetWithPathID(name string, script []byte, pathID int64) int64

AddTextAssetWithPathID 使用首选 PathID 添加 TextAsset 重打包已解包 .aba 时可用它保留内部 Unity PPtr 引用指向相同对象 AddTextAssetWithPathID adds a TextAsset using a preferred PathID It can preserve internal Unity PPtr targets when repacking extracted .aba files

func (*SerializedFileWriter) AddTexture2D

func (w *SerializedFileWriter) AddTexture2D(name string, width, height int64, imageData []byte) int64

AddTexture2D 添加一个 Texture2D 对象,imageData 是自上而下行序的 RGBA32 像素数据,width 和 height 是尺寸 返回分配的 PathID AddTexture2D adds a Texture2D with top-down RGBA32 imageData and the supplied width and height It returns the allocated PathID

func (*SerializedFileWriter) AddTexture2DWithLoadName

func (w *SerializedFileWriter) AddTexture2DWithLoadName(name string, loadName string, width, height int64, imageData []byte) int64

AddTexture2DWithLoadName 添加内部 m_Name 可不同于 AssetBundle m_Container LoadAsset 键的 Texture2D AddTexture2DWithLoadName adds a generated Texture2D whose internal m_Name can differ from the AssetBundle m_Container key used by LoadAsset

func (*SerializedFileWriter) AddTexture2DWithLoadNameAndPathID

func (w *SerializedFileWriter) AddTexture2DWithLoadNameAndPathID(name string, loadName string, width, height int64, imageData []byte, pathID int64) int64

AddTexture2DWithLoadNameAndPathID 添加带独立 m_Name、AssetBundle 加载键和首选 PathID 的 Texture2D,imageData 按自上而下行序传入并翻转为 Unity 自下而上行序 AddTexture2DWithLoadNameAndPathID adds a generated Texture2D with separate internal m_Name, AssetBundle load key, and preferred PathID, taking imageData in top-down row order and flipping it into Unity's bottom-up row order

func (*SerializedFileWriter) AddTexture2DWithPathID

func (w *SerializedFileWriter) AddTexture2DWithPathID(name string, width, height int64, imageData []byte, pathID int64) int64

AddTexture2DWithPathID 使用首选 PathID 添加生成的 Texture2D AddTexture2DWithPathID adds a generated Texture2D with a preferred PathID

func (*SerializedFileWriter) SetExternalFiles

func (w *SerializedFileWriter) SetExternalFiles(externalFiles []ExternalFile)

SetExternalFiles 设置 metadata 外部文件表并复制输入,使后续调用方修改不会改变写入结果 SetExternalFiles sets the metadata external-file table and copies the input so later caller mutations cannot alter the output

func (*SerializedFileWriter) Size

func (w *SerializedFileWriter) Size() (int64, error)

Size 计算完整 SerializedFile 的精确字节数且不读取流式对象数据 Size computes the exact complete SerializedFile byte size without reading streamed object data

func (*SerializedFileWriter) Write

func (w *SerializedFileWriter) Write(out io.Writer) error

Write 将所有对象写入完整的 SerializedFile v22 格式,并自动追加 ClassID 142 AssetBundle 对象作为 m_Container 映射 Write emits a complete SerializedFile v22 and appends a ClassID 142 AssetBundle object containing the m_Container mapping

type SerializedObjectDataSource

type SerializedObjectDataSource struct {
	Size    uint32                    // 对象在线格式字节数 / Object byte size on the wire
	Prefix  []byte                    // 用于读取稳定基类字段的对象前缀 / Object prefix used to inspect stable base fields
	WriteTo SerializedObjectWriteFunc // 每次调用都写出恰好 Size 字节的回调 / Callback that writes exactly Size bytes on every call
}

SerializedObjectDataSource 描述无需整体载入内存的序列化对象数据源 / SerializedObjectDataSource describes a serialized object source that does not need to be loaded completely into memory

type SerializedObjectWriteFunc

type SerializedObjectWriteFunc func(io.Writer) error

SerializedObjectWriteFunc 将一个对象的完整序列化字节写入目标 SerializedObjectWriteFunc writes the complete serialized bytes of one object to a destination

type SpriteExport

type SpriteExport struct {
	Name        string         // Sprite 名称 / Sprite name
	Texture     *Texture2DData // 源 Texture2D 数据 / Source Texture2D data
	Rect        SpriteRect     // 裁剪矩形 / Crop rectangle
	SettingsRaw uint32         // Unity SpriteSettings 原始位标志 / Raw Unity SpriteSettings flags
}

SpriteExport 描述从 Texture2D 或 SpriteAtlas 裁剪出的 Sprite SpriteExport describes a Sprite cropped from a Texture2D or SpriteAtlas

type SpriteRect

type SpriteRect struct {
	X      float32 // 左下角 X 坐标 / Lower-left X coordinate
	Y      float32 // 左下角 Y 坐标 / Lower-left Y coordinate
	Width  float32 // 宽度 / Width
	Height float32 // 高度 / Height
}

SpriteRect 使用原点位于左下角的 Unity 贴图坐标 SpriteRect uses Unity texture coordinates with the origin at the lower-left corner

type StreamingInfo

type StreamingInfo struct {
	Offset int64  // sidecar 文件内偏移 / Offset inside the sidecar file
	Size   uint64 // 数据大小,AudioClip 在线格式使用 UInt64 / Payload size, stored as UInt64 by the AudioClip wire format
	Path   string // sidecar 文件路径 / Sidecar file path
}

StreamingInfo 表示 Unity 对象指向 .resS、.resource 或 .resources 条目的流式载荷范围 / StreamingInfo represents a streamed payload range in a Unity .resS, .resource, or .resources entry

type Texture2DData

type Texture2DData struct {
	Name          string        // 贴图名称 / Texture name
	Width         int32         // 贴图宽度 / Texture width
	Height        int32         // 贴图高度 / Texture height
	TextureFormat int32         // Unity TextureFormat 枚举值 / Unity TextureFormat enum value
	MipCount      int32         // mipmap 层数 / Mipmap count
	ImageData     []byte        // 原始编码图像数据 / Raw encoded image data
	StreamData    StreamingInfo // 外部流式数据引用 / External streamed data reference
}

Texture2DData 是导出 Unity Texture2D 所需的字段子集 / Texture2DData is the subset of Unity Texture2D fields needed for export

type TypeTreeNode

type TypeTreeNode struct {
	Version     uint16 // 节点版本 / Node version
	Level       byte   // 层级深度 / Tree depth level
	TypeFlags   byte   // 类型标志,0x01 表示 IsArray / Type flags, with 0x01 meaning IsArray
	TypeStrOff  uint32 // 类型名在字符串缓冲区中的偏移 / Offset of the type name in the string buffer
	NameStrOff  uint32 // 字段名在字符串缓冲区中的偏移 / Offset of the field name in the string buffer
	ByteSize    int32  // 字段字节大小,-1 表示可变长度 / Field byte size, with -1 meaning variable length
	Index       int32  // 在父节点中的索引 / Index within the parent node
	MetaFlags   uint32 // 元标志,0x4000 表示 AlignBytes / Metadata flags, with 0x4000 meaning AlignBytes
	RefTypeHash uint64 // v19+ 引用类型哈希 / Referenced-type hash in v19+
}

TypeTreeNode 表示 Unity TypeTree 中的一个节点 / TypeTreeNode represents one node in a Unity TypeTree

type TypeTreeType

type TypeTreeType struct {
	TypeId           int32          // 类型 ID,如 28=Texture2D、49=TextAsset / Class ID such as 28=Texture2D and 49=TextAsset
	IsStrippedType   bool           // 是否被剥离 / Whether this type is stripped
	ScriptTypeIndex  int16          // 脚本类型索引,-1 表示无脚本 / Script type index, with -1 meaning no script
	ScriptIdHash     [16]byte       // v13+ 脚本类型按条件保存的脚本 ID 哈希 / Conditionally stored script ID hash for script types in v13+
	TypeHash         [16]byte       // 类型哈希 / Type hash
	Nodes            []TypeTreeNode // 仅在 TypeTreeEnabled 为 true 时保存的类型树节点 / Type-tree nodes stored only when TypeTreeEnabled is true
	StringBuffer     []byte         // 字符串缓冲区 / String buffer
	TypeDependencies []int32        // v21+ 且启用 TypeTree 时的普通类型依赖 / Ordinary type dependencies for v21+ with TypeTree enabled
	ClassName        string         // 引用类型类名 / Referenced type class name
	Namespace        string         // 引用类型命名空间 / Referenced type namespace
	AssemblyName     string         // 引用类型程序集名 / Referenced type assembly name
}

TypeTreeType 表示一个 Unity 类型的 TypeTree 定义 / TypeTreeType represents the TypeTree definition for one Unity type

func (*TypeTreeType) GetTypeTreeString

func (tt *TypeTreeType) GetTypeTreeString(node *TypeTreeNode, isType bool) string

GetTypeTreeString 从 StringBuffer 或 Unity 内置公共字符串表解析类型树节点字符串 GetTypeTreeString resolves a type-tree node string from StringBuffer or Unity's built-in common string table

type TypeTreeValue

type TypeTreeValue struct {
	TypeName   string           // Unity 类型名 / Unity type name
	Name       string           // 字段名或节点名 / Field or node name
	Value      interface{}      // 原始标量值或字节数组 / Raw scalar value or byte array
	Children   []*TypeTreeValue // 子节点列表 / Child node list
	NodeIndex  int64            // 对应 TypeTree 节点索引 / Corresponding TypeTree node index
	ByteOffset int64            // 值在对象数据中的起始偏移 / Start offset of the value in object data
	ByteSize   int64            // 值及其尾部对齐占用的字节数 / Byte count occupied by the value and trailing alignment
}

TypeTreeValue 是根据内嵌 TypeTree 解码且仅暴露 KCES 所需导航 API 的 Unity 序列化值 / TypeTreeValue is a Unity serialized value decoded from an embedded TypeTree with only the navigation API needed by KCES

func (*TypeTreeValue) Bytes

func (v *TypeTreeValue) Bytes() ([]byte, bool)

Bytes 返回节点中的原始字节,或将子节点整数转换为字节数组 Bytes returns raw bytes in the node or converts integer child nodes to a byte array

func (*TypeTreeValue) Field

func (v *TypeTreeValue) Field(name string) *TypeTreeValue

Field 返回名称匹配的第一个直接子节点 Field returns the first direct child with the requested field name

func (*TypeTreeValue) FieldPath

func (v *TypeTreeValue) FieldPath(names ...string) *TypeTreeValue

FieldPath 按字段名依次遍历直接子节点 FieldPath walks through direct children by field names

func (*TypeTreeValue) Float32

func (v *TypeTreeValue) Float32() (float32, bool)

Float32 将 Float32 或 Float64 节点值转换为 Float32 Float32 converts a Float32 or Float64 node value to Float32

func (*TypeTreeValue) Int64

func (v *TypeTreeValue) Int64() (int64, bool)

Int64 将支持的有符号或可表示无符号整数转换为 Int64 Int64 converts supported signed or representable unsigned integers to Int64

func (*TypeTreeValue) String

func (v *TypeTreeValue) String() (string, bool)

String 将节点值断言为字符串并返回是否成功 String asserts the node value as a string and reports whether it succeeded

func (*TypeTreeValue) UInt64

func (v *TypeTreeValue) UInt64() (uint64, bool)

UInt64 返回非负整数,并保留大于 MaxInt64 的 UInt64 值 UInt64 returns a non-negative integer without losing values above MaxInt64

Jump to

Keyboard shortcuts

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