Tutorial¶
Using a ReadWriteFile Class¶
The most common way of working with video game file formats in the
vgio library is a class derived from the
ReadWriteFile class. You can create instances of this
class by loading from a file or from scratch.
To load a video game file format object from a file use the
open(file, mode='r') classmethod on the derived
ReadWriteFile class. Because
ReadWriteFile is a base class this example will use the
Quake Mdl model format:
>>> from vgio.quake.mdl import Mdl
>>> mdl_file = Mdl.open('armor.mdl')
If successful, it will return an Mdl object. You
can now use instance attributes to examine the file contents:
>>> print(mdl_file.version)
6
>>> print(mdl_file.identifier)
b'IDPO'
Using an ArchiveFile Class¶
It is common for video games to bundle their files in an archive and
the vgio library provides classes derived from
ArchiveFile and ArchiveInfo to
work with that data.
Note
An ArchiveFile object must be created using a file or
file-like object.
Since the ArchiveFile is a base class, this example will
use the Duke3D GrpFile archive format:
>>> from vgio.duke3d.grp import GrpFile
>>> grp_file = GrpFile('DUKE3D.GRP')
If successful, it will return an GrpFile object.
You can now get a GrpInfo object and can use the
instance attributes to examine the file contents:
>>> info = grp_file.infolist()[0]
>>> print(info.filename)
LOGO.ANM
>>> print(info.file_size)
1507336