Bases: pyffi.object_models.xml.FileFormat
This class implements the kfm file format.
Bases: pyffi.formats.kfm._Header, pyffi.object_models.Data
A class to contain the actual kfm data.
Display the nif file name.
Quick heuristic check if stream contains KFM data, by looking at the first 64 bytes. Sets version and reads header string.
Parameters: | stream (file) – The stream to inspect. |
---|
Read a kfm file.
Parameters: | stream (file) – The stream from which to read. |
---|
Write a kfm file.
Parameters: | stream (file) – The stream to which to write. |
---|
Bases: pyffi.object_models.xml.basic.BasicBase
The kfm header string.
Return a hash value for this value.
Returns: | An immutable object that can be used as a hash. |
---|
Return number of bytes the header string occupies in a file.
Returns: | Number of bytes. |
---|
Read header string from stream and check it.
Parameters: |
|
---|
Transforms version number into a version string.
Parameters: | version (int) – The version number. |
---|---|
Returns: | A version string. |
>>> KfmFormat.HeaderString.version_string(0x0202000b)
';Gamebryo KFM File Version 2.2.0.0b'
>>> KfmFormat.HeaderString.version_string(0x01024b00)
';Gamebryo KFM File Version 1.2.4b'
Write the header string to stream.
Parameters: | stream (file) – The stream to write to. |
---|
Bases: pyffi.object_models.xml.basic.BasicBase, pyffi.object_models.editable.EditableLineEdit
Basic type for strings. The type starts with an unsigned int which describes the length of the string.
>>> from tempfile import TemporaryFile
>>> f = TemporaryFile()
>>> from pyffi.object_models import FileFormat
>>> data = FileFormat.Data()
>>> s = SizedString()
>>> if f.write('\x07\x00\x00\x00abcdefg'.encode("ascii")): pass # ignore result for py3k
>>> if f.seek(0): pass # ignore result for py3k
>>> s.read(f, data)
>>> str(s)
'abcdefg'
>>> if f.seek(0): pass # ignore result for py3k
>>> s.set_value('Hi There')
>>> s.write(f, data)
>>> if f.seek(0): pass # ignore result for py3k
>>> m = SizedString()
>>> m.read(f, data)
>>> str(m)
'Hi There'
Return a hash value for this string.
Returns: | An immutable object that can be used as a hash. |
---|
Return number of bytes this type occupies in a file.
Returns: | Number of bytes. |
---|
Return the string.
Returns: | The stored string. |
---|
Read string from stream.
Parameters: | stream (file) – The stream to read from. |
---|
Set string to C{value}.
Parameters: | value (str) – The value to assign. |
---|
Write string to stream.
Parameters: | stream (file) – The stream to write to. |
---|
alias of UndecodedData
alias of UByte
alias of Char
alias of Float
alias of Int
alias of Short
alias of UInt
alias of UShort
Converts version string into an integer.
Parameters: | version_str (str) – The version string. |
---|---|
Returns: | A version integer. |
>>> hex(KfmFormat.version_number('1.0'))
'0x1000000'
>>> hex(KfmFormat.version_number('1.2.4b'))
'0x1024b00'
>>> hex(KfmFormat.version_number('2.2.0.0b'))
'0x202000b'
>>> # read kfm file
>>> stream = open('tests/kfm/test.kfm', 'rb')
>>> data = KfmFormat.Data()
>>> data.inspect(stream)
>>> print(data.nif_file_name.decode("ascii"))
Test.nif
>>> data.read(stream)
>>> stream.close()
>>> # get all animation file names
>>> for anim in data.animations:
... print(anim.kf_file_name.decode("ascii"))
Test_MD_Idle.kf
Test_MD_Run.kf
Test_MD_Walk.kf
Test_MD_Die.kf
>>> for stream, data in KfmFormat.walkData('tests/kfm'):
... print(stream.name)
tests/kfm/test.kfm
>>> data = KfmFormat.Data()
>>> data.nif_file_name = "Test.nif"
>>> data.num_animations = 4
>>> data.animations.update_size()
>>> data.animations[0].kf_file_name = "Test_MD_Idle.kf"
>>> data.animations[1].kf_file_name = "Test_MD_Run.kf"
>>> data.animations[2].kf_file_name = "Test_MD_Walk.kf"
>>> data.animations[3].kf_file_name = "Test_MD_Die.kf"
>>> from tempfile import TemporaryFile
>>> stream = TemporaryFile()
>>> data.write(stream)
>>> stream.close()
>>> for vnum in sorted(KfmFormat.versions.values()):
... print('0x%08X' % vnum)
0x01000000
0x01024B00
0x0200000B
0x0201000B
0x0202000B
>>> for game, versions in sorted(KfmFormat.games.items(),
... key=lambda x: x[0]):
... print("%s " % game + " ".join('0x%08X' % vnum for vnum in versions))
Civilization IV 0x01000000 0x01024B00 0x0200000B
Emerge 0x0201000B 0x0202000B
Loki 0x01024B00
Megami Tensei: Imagine 0x0201000B
Oblivion 0x01024B00
Prison Tycoon 0x01024B00
Pro Cycling Manager 0x01024B00
Red Ocean 0x01024B00
Sid Meier's Railroads 0x0200000B
The Guild 2 0x01024B00