2016-02-26 18:05:51 +00:00
|
|
|
"""Allegedly stands for 'Pokémon Container'. Completely generic, dead-simple
|
|
|
|
container format.
|
|
|
|
"""
|
|
|
|
from .base import _ContainerFile, Substream
|
|
|
|
|
|
|
|
|
|
|
|
class PokemonContainerFile(_ContainerFile):
|
|
|
|
magic = b'PC'
|
|
|
|
|
|
|
|
def __init__(self, stream):
|
|
|
|
self.stream = stream = Substream(stream)
|
|
|
|
|
|
|
|
magic, entry_ct = stream.unpack('<2sH')
|
|
|
|
assert magic == b'PC'
|
|
|
|
|
2016-12-20 00:18:53 +00:00
|
|
|
# Offsets are "A B C ...", where entry 0 ranges from A to B, entry 1
|
|
|
|
# from B to C, etc.
|
|
|
|
offsets = stream.unpack('<{}L'.format(entry_ct + 1))
|
2016-02-26 18:05:51 +00:00
|
|
|
self.slices = []
|
2016-12-20 00:18:53 +00:00
|
|
|
for i in range(entry_ct):
|
|
|
|
start, end = offsets[i:i + 2]
|
2016-02-26 18:05:51 +00:00
|
|
|
self.slices.append(self.stream.slice(start, end - start))
|