Documentation
¶
Index ¶
- Constants
- func AxisName(axis uint8) string
- func DecodePackedOperand(operand uint32) (pieceID, axis, value, flags uint8)
- func EncodePackedOperand(pieceID, axis, value, flags uint8) uint32
- func OpcodeByName(name string) (uint32, bool)
- func OpcodeHasInlineParam(opcode uint32) bool
- func OpcodeName(opcode uint32) string
- func OpcodeParamCount(opcode uint32) int
- type COB
- type Instruction
Constants ¶
const ( // Animation commands - object manipulation OP_MOVE = 0x10001000 // Move object (speed & distance from stack, then piece#, axis#) OP_TURN = 0x10002000 // Turn object (speed & direction from stack, then piece#, axis#) OP_SPIN = 0x10003000 // Spin object (speed from stack, then piece#, axis#) OP_STOP_SPIN = 0x10004000 // Stop spin (piece#, axis# after) OP_SHOW = 0x10005000 // Show object (piece# after) OP_HIDE = 0x10006000 // Hide object (piece# after) OP_CACHE = 0x10007000 // Cache object (piece# after) OP_DONT_CACHE = 0x10008000 // Don't cache (piece# after) OP_TURN_NOW = 0x1000C000 // Turn immediately (piece#, axis#, angle after) OP_MOVE_NOW = 0x1000B000 // Move immediately (piece#, axis#, position after) OP_SHADE = 0x1000D000 // Shade object (piece# after) OP_DONT_SHADE = 0x1000E000 // Don't shade (piece# after) OP_EMIT_SFX = 0x1000F000 // Emit SFX (type from stack, then piece#) // Wait operations OP_WAIT_FOR_TURN = 0x10011000 // Wait for turn (piece#, axis# after) OP_WAIT_FOR_MOVE = 0x10012000 // Wait for move (piece#, axis# after) OP_SLEEP = 0x10013000 // Sleep (time from stack) // Stack operations OP_PUSH_CONSTANT = 0x10021001 // Push constant <value> OP_PUSH_LOCAL_VAR = 0x10021002 // Push local var <var#> OP_PUSH_STATIC = 0x10021004 // Push static var <var#> OP_CREATE_LOCAL = 0x10021008 // Create local variable OP_PUSH_IMMEDIATE = 0x10021000 // Push immediate (value after) OP_STACK_ALLOC = 0x10022000 // Allocate local variable (no param) OP_POP_LOCAL_VAR = 0x10023002 // Pop to local var <var#> OP_POP_STATIC = 0x10023004 // Pop to static var <var#> OP_POP_STACK = 0x10024000 // Pop and discard top of stack // Arithmetic operations OP_ADD = 0x10031000 // Add (both from stack) OP_SUB = 0x10032000 // Subtract (both from stack) OP_MUL = 0x10033000 // Multiply (both from stack) OP_DIV = 0x10034000 // Divide (both from stack) OP_MOD = 0x10037000 // Modulo (both from stack) // Bitwise operations OP_BITWISE_AND = 0x10035000 // Bitwise AND OP_BITWISE_OR = 0x10036000 // Bitwise OR OP_BITWISE_XOR = 0x10038000 // Bitwise XOR OP_BITWISE_NOT = 0x1003A000 // Bitwise NOT // Special functions OP_RAND = 0x10041000 // Random (low & high from stack) OP_GET_UNIT_VALUE = 0x10042000 // Get unit value (port# from stack) OP_GET = 0x10043000 // Get value // Comparison operations OP_LESS_THAN = 0x10051000 // < (both from stack) OP_LESS_OR_EQUAL = 0x10052000 // <= (both from stack) OP_GREATER_THAN = 0x10053000 // > (both from stack) OP_GREATER_EQUAL = 0x10054000 // >= (both from stack) OP_EQUAL = 0x10055000 // == (both from stack) OP_NOT_EQUAL = 0x10056000 // != (both from stack) // Logical operations OP_LOGICAL_AND = 0x10057000 // && (both from stack) OP_LOGICAL_OR = 0x10058000 // || (both from stack) OP_LOGICAL_XOR = 0x10059000 // ^^ (both from stack) OP_LOGICAL_NOT = 0x1005A000 // ! (from stack) // Control flow OP_START_SCRIPT = 0x10061000 // Start script (params from stack, then script#, param_count) OP_CALL_SCRIPT = 0x10062000 // Call script — actual value found in TA COB files (0x10062000, not 0x10063000 as documented) OP_JUMP = 0x10064000 // Jump <offset> OP_RETURN = 0x10065000 // Return (value from stack) OP_JUMP_IF_FALSE = 0x10066000 // Jump if false (test from stack, <offset>) OP_SIGNAL = 0x10067000 // Signal (signal# from stack) OP_SET_SIGNAL_MASK = 0x10068000 // Set signal mask (mask from stack) // Special effects OP_EXPLODE = 0x10071000 // Explode (type from stack, then piece#) OP_PLAY_SOUND = 0x10072000 // Play sound (sound# from stack, volume after) // Set operations OP_SET_VALUE = 0x10082000 // Set unit value (port# from stack, value from stack) OP_ATTACH_UNIT = 0x10083000 // Attach unit (piece# after) OP_DROP_UNIT = 0x10084000 // Drop unit // DONT_SHADOW disables shadow casting for a single piece. It shares the // shape of the other animation opcodes (one inline piece# DWORD) and // only appears in retail TA: Kingdoms .cob files (Scriptor's keyword // `dont-shadow` lives in the same animation category as `dont-shade`). OP_DONT_SHADOW = 0x1000A000 // MISSION_COMMAND invokes a named TAK engine command. Two inline DWORDs // encode (soundNameIndex, stackArgCount); the engine pops `stackArgCount` // values off the stack, executes the command stored at index // `soundNameIndex` of the per-COB sound-name table, and pushes a result // back. The result is consumed by whichever POP_* opcode follows // (POP_STATIC/POP_LOCAL for assignment, POP_STACK to discard). Maps to // Scriptor's `Mission-Command(STRING, args...)` keyword. OP_MISSION_COMMAND = 0x10073000 // OP_TAK_MATH_09 / OP_TAK_MATH_0B are TAK-only math opcodes whose exact // semantics have not been documented. Scriptor labels them `??` / `????`, // so even the canonical TAK-aware tool treats them as opaque operators. // Empirically every retail .cob site uses them as stack-neutral // pseudo-ops wrapping a producing expression — that's how we round-trip // them through decompile/compile. OP_TAK_MATH_09 = 0x10039000 OP_TAK_MATH_0B = 0x1003B000 )
Variables ¶
This section is empty.
Functions ¶
func DecodePackedOperand ¶
DecodePackedOperand extracts components from packed animation opcodes Format: [piece_id:8][axis:8][speed_or_value:8][flags:8]
func EncodePackedOperand ¶
EncodePackedOperand packs piece, axis, value, flags into a single uint32
func OpcodeByName ¶
OpcodeByName returns the opcode value for a given opcode name
func OpcodeHasInlineParam ¶
OpcodeHasInlineParam returns true if the opcode has inline parameters (Post Data)
func OpcodeName ¶
OpcodeName returns the mnemonic name for an opcode
func OpcodeParamCount ¶
OpcodeParamCount returns how many DWORDs of parameters follow the opcode
Types ¶
type COB ¶
type COB struct {
// Header fields (11 DWORDs for TA's VersionSignature=4 files; TA: Kingdoms
// uses VersionSignature=6 and inserts an 8-byte sub-header before the code
// section plus a per-COB sound-name table after the piece names — both
// are reconstructed from the structured fields below, not preserved as
// opaque bytes.)
VersionSignature uint32 // [0] Version (4 for TA, 6 for TA: Kingdoms)
NumScripts uint32 // [1] Number of scripts
NumPieces uint32 // [2] Number of pieces
LengthOfScripts uint32 // [3] Total code size in DWORDs
NumberOfStaticVars uint32 // [4] Number of static variables
UKZero uint32 // [5] Always 0 in retail bytecode; purpose unknown
OffsetToScriptCodeIndexArray uint32 // [6] Offset to script index array
OffsetToScriptNameOffsetArray uint32 // [7] Offset to script name array (ABSOLUTE offsets)
OffsetToPieceNameOffsetArray uint32 // [8] Offset to piece name array (ABSOLUTE offsets)
OffsetToScriptCode uint32 // [9] Offset to script code
OffsetToNameArray uint32 // [10] Start of the trailing offset/string region (begins at the sound-name offset table for v6, otherwise the script-name pool start)
// Parsed data
Code []byte
ScriptCodeIndices []uint32 // Indices from OffsetToScriptCodeIndexArray
ScriptNames []string
PieceNames []string
// SoundNames is the TA: Kingdoms–only addendum to the string pool.
// v6 .cob files insert a `len(SoundNames)` × uint32 offset table
// after the piece-name offset array (pointed at by the 8-byte extra
// sub-header at file offset 0x2C), followed by the actual strings in
// order. The MISSION_COMMAND opcode (0x10073000) references them by
// index via its first inline DWORD; the offset table and sub-header
// are reconstructed from this slice on write — for TA's v4 .cob files
// the slice is always nil and the wrapping pieces are omitted.
SoundNames []string
}
COB represents a compiled BOS script (Total Annihilation format).
func LoadFromFile ¶
LoadFromFile reads a COB file from the local filesystem
func LoadFromFilesystem ¶
func LoadFromFilesystem(fs filesystem.FileSystem, path string) (*COB, error)
LoadFromFilesystem reads a COB file from a virtual filesystem
func LoadFromReader ¶
LoadFromReader reads a COB from an io.Reader (streaming) Instruction represents a single disassembled COB instruction.
func (*COB) Disassemble ¶
func (c *COB) Disassemble(scriptIndex int) ([]Instruction, error)
Disassemble disassembles the bytecode into instructions
func (*COB) SaveToFile ¶
SaveToFile writes the COB to a file
func (*COB) WriteToWriter ¶
WriteToWriter writes the COB to a writer.
The on-disk layout is fully reconstructed from the structured fields — no opaque-byte preservation. For TA's v4 dialect:
header (44) · code · script-code-index array · script-name offsets · piece-name offsets · string pool
For TA: Kingdoms v6 .cob files an 8-byte sub-header (sound-name offset-table location + count) is inserted between the canonical header and the code section, and the trailing layout grows a sound-name offset table immediately after the piece-name array. The string pool is laid out script names → piece names → sound names, in that order, with all offsets and the v6 sub-header reconstructed from the structured fields below.
type Instruction ¶
type Instruction struct {
Offset uint32
Opcode uint32 // Full 32-bit nTA opcode
Operand int32 // First 32-bit parameter (for 1-param opcodes)
Operand2 int32 // Second 32-bit parameter (for 2-param opcodes like TURN)
}
Instruction represents a single COB bytecode instruction (nTA format)
func (Instruction) String ¶
func (i Instruction) String() string
String returns a string representation of the instruction (TA COB format)