XPlor/definitions/asura/chunks/fcsr_chunk.xscript

58 lines
1.9 KiB
Plaintext
Raw Normal View History

// FCSR - File/Resource Chunk (reversed "RSCF")
// Contains embedded file data with path and type information
// Primary chunk type for storing assets in Asura archives
type fcsr_chunk [display="FCSR Resource"] byteorder BE
{
// Save chunk start position
chunk_start = pos();
// Standard 16-byte Asura chunk header
chunk_id = ascii(read(4));
u32 chunk_size;
u32 version;
u32 flags;
chunk_id = chunk_id [ui, readonly, display="Chunk ID"];
chunk_size = chunk_size [ui, readonly, display="Chunk Size"];
version = version [ui, readonly, display="Version"];
flags = flags [ui, readonly, display="Flags"];
// Resource metadata
u32 resource_type;
u32 unknown1;
u32 resource_size;
resource_type = resource_type [ui, readonly, display="Resource Type"];
unknown1 = unknown1 [ui, readonly, display="Unknown"];
resource_size = resource_size [ui, readonly, display="Resource Size"];
// Resource file path (null-terminated)
resource_path = cstring();
resource_path = resource_path [ui, readonly, display="Resource Path"];
// Get filename from path and set as chunk name for tree display
export_name = basename(resource_path);
_name = export_name;
// Calculate where resource data starts
resource_offset = chunk_start + chunk_size - resource_size;
// Export resource if size > 0
if (resource_size > 0 && resource_offset >= pos()) {
// Seek to resource data
seek(resource_offset);
// Read resource data
resource_data = read(resource_size);
// Export the file
write_file(export_name, resource_data);
// Preview if it's an image file
if (ends_with(export_name, ".tga") || ends_with(export_name, ".dds") || ends_with(export_name, ".png") || ends_with(export_name, ".jpg") || ends_with(export_name, ".bmp")) {
preview(export_name, resource_data);
}
}
}