autoangel
AutoAngel is a general-purpose library designed to make it easy to work with angelica engine game files.
It supports the following file formats:
elements.data- load withread_elements, view, modify and save through theElementsDataobject.*.pck/*.pkx- load withread_pck, explore through thePckPackageobject.
Quick Start
Working with elements.data
Let's start with importing autoangel:
import autoangel
Now you can load any elements.data you want using read_elements:
data = autoangel.read_elements('/path/to/elements.data')
By default read_elements will try to use one of the bundled config.
This should work for you, if you don't use exotic game version (otherwise, you should load config with read_elements_config and pass it manually).
You can inspect data:
print(f'Version: {data.version}')
print(f'Number of lists: {len(data)}')
You can explore all the entries among all the lists. For example:
weapons_list = data[3]
# print list name
print(f'List: {weapons_list.config.caption}')
# print first 10 entries in list
for i in range(10):
weapon = weapons_list[i]
print(f'ID: {weapon.ID}, name: {weapon.Name}')
You can also modify anything you want like changing durability of all the weapons:
for weapon in weapons_list:
weapon.durability_min = weapon.durability_max = 99999
All the modifications won't affect original elements.data until you save it:
data.save('elements2.data')
Working with pck/pkx
You can load a pck package using read_pck:
import autoangel
# Load a single pck file
package = autoangel.read_pck('/path/to/package.pck')
# Load a pck file with its corresponding pkx file
package = autoangel.read_pck('/path/to/package.pck', '/path/to/package.pkx')
Once you have a PckPackage object, you can explore its contents:
# Get a list of all files in the package
file_list = package.file_list()
print(f'Number of files: {len(file_list)}')
# Find files with a specific prefix
textures = package.find_prefix('textures/')
print(f'Number of texture files: {len(textures)}')
# Get the content of a specific file
file_content = package.get_file('path/to/file.txt')
if file_content is not None:
print(f'File content: {file_content.decode("utf-8")}')
else:
print('File not found')
Configuration for elements.data.
Attributes:
- lists: elements.data lists configs
- name: name of config specified when parsing it (i.e. file name)
Object describing parsed elements.data. It also works as immutable array of data lists (ElementsDataList).
Implements basic list interface such as len(..) and __getitem__.
Attributes:
- version: elements.data version
See also: ElementsDataList
Find entry by ID and space ID.
Parameters
- id: Entry ID
- space_id: Optional space ID (
Noneby default). IfNone, find among all the lists, otherwise - only in lists with specified space_id. - allow_unknown: If set, include lists with
"unknown"space_id in search, otherwise - ignore them (Trueby default).
Returns
Found entry or
None
Single data entry.
Implements basic dict[str, object]-like and object-like interface such as len(..), __getattr__, __setattr__, __getitem__, __setitem__ and __contains__.
Number of fields, its names and types depend on elements.data version and list config.
Use entry.keys() to get field names.
One can access fields with either entry['name'] (by key) or entry.name (as an attribute) syntax.
Each field can be read and modified and has one of the following types:
intfloatstrbytes
See also: ElementsListConfig
Contains data of specific list in elements.data such as list info (like ElementsListConfig) and
all data entries (ElementsDataEntry). Implements basic list interface such as len(..), __getitem__ and __setitem__.
Attributes:
- config: list config
See also: ElementsDataEntry.
Configuration for a list in elements.data.
Attributes:
- caption: list caption
- data_type: list data type
- fields: array of fields
- offset: list offset
- space_id: list space id (may be
"unknown")
Array of list configurations.
Field metadata.
Attributes:
- name: field name
- type: field type
Array of field metadata.
Configuration for pck package encryption keys and guard values.
Object describing parsed pck package.
Returns list of file paths in package.
Returns
All paths in package.
Finds all files in archive with path prefixed by prefix.
Parameters
- prefix: Path prefix.
Returns
All paths in package prefixed by
prefixor empty list if no files were found.
Get file content by its path.
Parameters
- path: Path to file inside package.
Returns
Noneif file not found. Otherwise, returns file content.
Save the package to a file.
This method saves the package to a file at the specified path. The saved package will be identical to the original when loaded back.
Parameters
- path: Path where to save the package.
- config: Custom package configuration. Defaults to None.
Raises
- Exception: If any I/O error occurs during saving.
Parses elements.data from file elements_path and returns ElementsData.
Doesn't load file content into memory, uses memory-mapped I/O - so file cannot be modified while ElementsData is alive.
Parameters
- elements_path: Path to elements.data.
- config: Optional config describing elements.data structure (
Noneby default). If no config specified, one of predefined will be used.
Returns
Object describing parsed elements.data.
Raises
- Exception: If any I/O error occurs, elements.data has invalid internal structure or config has incompatible version.
Parses elements.data from byte array content and returns ElementsData.
Parameters
- content: Content of elements.data.
- config: Optional config describing elements.data structure (
Noneby default). If no config specified, one of predefined will be used.
Returns
Object describing parsed elements.data.
Raises
- Exception: If elements.data has invalid internal structure or config has incompatible version.
Parses elements.data config from file at path path and returns ElementsConfig describing parsed file.
Parameters
- path: Path to elements config.
Returns
Object describing parsed config.
Raises
- Exception: If any I/O error occurs or config has invalid internal structure.
Parses elements.data config from string content and returns ElementsConfig describing parsed file.
Parameters
- content: String containing elements config.
Returns
Object describing parsed config.
Raises
- Exception: If config has invalid internal structure.
Parses pck package from file at path pck_path (and optionally pkx_path) and returns PckPackage describing parsed file(s).
Doesn't load file content into memory, uses memory-mapped I/O - so file(s) cannot be modified while PckPackage is alive.
Parameters
- pck_path: Path to pck package.
- pkx_path: Optional path to pkx package (
Noneby default). - config: Custom package configuration. Defaults to None.
Returns
Object describing parsed package.
Raises
- Exception: If any I/O error occurs or package has invalid internal structure.
Parses package from byte array content and returns PckPackage.
Parameters
- content: Content of package.
- config: Custom package configuration. Defaults to None.
Returns
Object describing parsed package.
Raises
- Exception: If package has invalid internal structure.