本文整理汇总了Python中cuwo.bytes.ByteReader类的典型用法代码示例。如果您正苦于以下问题:Python ByteReader类的具体用法?Python ByteReader怎么用?Python ByteReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ByteReader类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_static_entities
def test_static_entities(self):
with open('./tests/tgen_static.dat', 'rb') as fp:
data = zlib.decompress(fp.read())
reader = ByteReader(data)
source = []
while reader.get_left() > 0:
entity = StaticEntityHeader()
entity.read(reader)
source.append(entity)
chunk = tgen.generate(32803, 32803)
self.assertEqual(len(chunk.static_entities), len(source))
for index, entity in enumerate(chunk.static_entities):
header1 = entity.header
header2 = source[index]
self.assertEqual(header1.entity_type, header2.entity_type)
self.assertEqual(header1.pos, header2.pos)
self.assertEqual(header1.orientation, header2.orientation)
self.assertEqual(header1.size, header2.size)
self.assertEqual(header1.closed, header2.closed)
self.assertEqual(header1.time_offset, header2.time_offset)
self.assertEqual(header1.something8, header2.something8)
self.assertEqual(header1.user_id, header2.user_id)
示例2: read
def read(self, reader):
size = reader.read_uint32()
decompressed_data = zlib.decompress(reader.read(size))
reader = ByteReader(decompressed_data)
self.items_1 = read_list(reader, Packet4Struct1)
self.player_hits = read_list(reader, HitPacket)
self.particles = read_list(reader, ParticleData)
self.sound_actions = read_list(reader, SoundAction)
self.shoot_actions = read_list(reader, ShootPacket)
self.items_6 = []
for _ in xrange(reader.read_uint32()):
self.items_6.append(reader.read(88))
self.chunk_items = read_list(reader, ChunkItems)
self.items_8 = []
for _ in xrange(reader.read_uint32()):
something = reader.read_uint64()
sub_items = []
for _ in xrange(reader.read_uint32()):
sub_items.append(reader.read(16))
self.items_8.append((something, sub_items))
self.pickups = read_list(reader, PickupAction)
self.kill_actions = read_list(reader, KillAction)
self.damage_actions = read_list(reader, DamageAction)
self.items_12 = []
for _ in xrange(reader.read_uint32()):
self.items_12.append(reader.read(40))
# objective/quests? not sure
self.missions = read_list(reader, MissionData)
debug = True
if debug:
v = vars(self).copy()
del v['pickups']
# del v['kill_actions']
del v['damage_actions']
del v['sound_actions']
del v['shoot_actions']
# del v['player_hits']
del v['chunk_items']
for k, v in v.iteritems():
if not v:
continue
print k, v
if len(decompressed_data) != reader.tell():
raise NotImplementedError()
示例3: feed
def feed(self, data):
self.data += data
reader = ByteReader(self.data)
while True:
pos = reader.tell()
if pos >= len(self.data):
break
try:
packet = read_packet(reader, self.table)
except OutOfData:
break
self.callback(packet)
self.data = self.data[pos:]
示例4: feed
def feed(self, data):
self.data += data
reader = ByteReader(self.data)
try:
while True:
pos = reader.tell()
if pos >= len(self.data):
break
packet = read_packet(reader, self.table)
self.callback(packet)
except OutOfData, e:
if e.reader is not reader:
raise e
示例5: feed
def feed(self, data):
self.data += data
reader = ByteReader(self.data)
while True:
pos = reader.tell()
if pos >= len(self.data):
break
try:
packet = read_packet(reader, self.table)
except OutOfData:
break
except KeyError, e:
print 'Last packet ID:', self.last_packet_id
raise e
self.last_packet_id = packet.packet_id
self.callback(packet)
示例6: feed
def feed(self, data):
self.data += data
reader = ByteReader(self.data)
try:
while True:
pos = reader.tell()
if pos >= len(self.data):
break
packet = read_packet(reader, self.table)
self.callback(packet)
if self.stopping:
return
except OutOfData as e:
if e.reader is not reader:
raise e
self.data = self.data[pos:]
示例7: test_static_entities
def test_static_entities(self):
with open('./tests/tgen_static.dat', 'rb') as fp:
data = zlib.decompress(fp.read())
reader = ByteReader(data)
source = []
while reader.get_left() > 0:
entity = StaticEntityHeader()
entity.read(reader)
source.append(entity)
chunk = tgen.generate(32803, 32803)
self.assertEqual(len(chunk.static_entities), len(source))
for index, entity in enumerate(chunk.static_entities):
header1 = entity.header
header2 = source[index]
self.assertEqual(header1.entity_type, header2.entity_type)
self.assertEqual(header1.pos, header2.pos)
self.assertEqual(header1.orientation, header2.orientation)
self.assertEqual(header1.size, header2.size)
self.assertEqual(header1.closed, header2.closed)
self.assertEqual(header1.time_offset, header2.time_offset)
self.assertEqual(header1.something8, header2.something8)
self.assertEqual(header1.user_id, header2.user_id)
events = [
('generate', (1007, 4974)),
('generate', (1007, 4973)),
('generate', (1007, 4972)),
('generate', (1007, 4971)),
('destroy', (1007, 4973)),
('generate', (1007, 4970)),
('destroy', (1007, 4972)),
('generate', (1007, 4969))
]
chunks = {}
for (event, chunk) in events:
if event == 'generate':
chunks[chunk] = tgen.generate(*chunk)
elif event == 'destroy':
chunks[chunk].destroy()
示例8: convert_qmo
def convert_qmo(path):
data = ByteReader(open(path, 'rb').read())
qmo_file = QubicleFile()
qmo_model = QubicleModel()
x_size, y_size, z_size = 256, 256, 256
qmo_model.x_size = x_size
qmo_model.y_size = y_size
qmo_model.z_size = z_size
qmo_model.x_offset = -x_size / 2
qmo_model.y_offset = 0
qmo_model.z_offset = -z_size / 2
min_z = None
max_z = None
for i in xrange(256*256):
something = data.read_float()
something2 = data.read_float()
something3 = data.read_float()
something4 = data.read_uint32()
something5 = data.read_uint32()
size = data.read_uint32()*4
chunk_data = data.read(size)
x = i % 256
y = i / 256
z = something4
if min_z is None or max_z is None:
min_z = z
max_z = z + len(chunk_data) / 4
else:
min_z = min(z, min_z)
max_z = max(max_z, len(chunk_data) / 4)
for i in xrange(len(chunk_data) / 4):
r = ord(chunk_data[i*4])
g = ord(chunk_data[i*4+1])
b = ord(chunk_data[i*4+2])
a = ord(chunk_data[i*4+3])
if a == 0:
z += 1
continue
qmo_model.blocks[switch_axes(x, y, z)] = (r, g, b)
z += 1
qmo_model.y_offset
qmo_file.models.append(qmo_model)
writer = ByteWriter()
qmo_file.write(writer)
name = os.path.splitext(os.path.basename(path))[0]
out_path = os.path.join('genqmo', name + '.qmo')
open(out_path, 'wb').write(writer.get())
print 'Converted', path
示例9: read
def read(self, reader):
size = reader.read_uint32()
decompressed_data = zlib.decompress(reader.read(size))
reader = ByteReader(decompressed_data)
self.block_actions = read_list(reader, BlockAction)
self.player_hits = read_list(reader, HitPacket)
self.particles = read_list(reader, ParticleData)
self.sound_actions = read_list(reader, SoundAction)
self.shoot_actions = read_list(reader, ShootPacket)
self.static_entities = read_list(reader, StaticEntityPacket)
self.chunk_items = read_list(reader, ChunkItems)
self.items_8 = []
for _ in range(reader.read_uint32()):
something = reader.read_uint64()
sub_items = []
for _ in range(reader.read_uint32()):
sub_items.append(reader.read(16))
self.items_8.append((something, sub_items))
self.pickups = read_list(reader, PickupAction)
self.kill_actions = read_list(reader, KillAction)
self.damage_actions = read_list(reader, DamageAction)
# EXT: used when NPC wizards/creatures use a right-click targeted
# action such as a spell cast. (NPC rclick action?)
self.passive_actions = read_list(reader, PassivePacket)
self.missions = read_list(reader, MissionPacket)
debug = False
if debug:
v = vars(self).copy()
# del v['kill_actions']
# del v['player_hits']
del v['pickups']
del v['damage_actions']
del v['sound_actions']
del v['shoot_actions']
del v['chunk_items']
for k, v in v.items():
if not v:
continue
print(k, v)
if len(decompressed_data) != reader.tell():
raise NotImplementedError()
示例10: update_entity
def update_entity(self, entity):
reader = ByteReader(self.data)
reader.skip(8)
read_masked_data(entity, reader)
示例11: read
def read(self, reader):
size = reader.read_uint32()
self.data = zlib.decompress(reader.read(size))
reader = ByteReader(self.data)
self.entity_id = reader.read_uint64()