def fast_forward(prologue, demo_io, tick=None): full_packets, remaining_packets = [], [] world = w.construct(prologue.recv_tables) string_tables = copy.deepcopy(prologue.string_tables) if tick: iter_bootstrap = iter(demo_io) try: while True: p, m = next(iter_bootstrap) if p.kind == pb_d.DEM_FullPacket: full_packets.append((p, m)) remaining_packets = [] else: remaining_packets.append((p, m)) if p.tick > tick - 2: # hack? break except StopIteration: raise EOFError() if full_packets: for peek, message in full_packets: full_packet = d_io.parse(peek.kind, peek.compressed, message) for table in full_packet.string_table.tables: assert not table.items_clientside entries = [(_i, e.str, e.data) for _i, e in enumerate(table.items)] string_tables[table.table_name].update_all(entries) peek, message = full_packets[-1] pbmsg = d_io.parse(peek.kind, peek.compressed, message) packet = i.construct(p_io.construct(pbmsg.packet.data)) peek, message = packet.find(pb_n.svc_PacketEntities) pe = p_io.parse(peek.kind, message) ct = pe.updated_entries bs = b_io.construct(pe.entity_data) unpacker = u_ent.construct(bs, -1, ct, False, prologue.class_bits, world) for index, mode, (cls, serial, diff) in unpacker: data = string_tables['instancebaseline'].get(cls)[1] bs = b_io.construct(data) unpacker = u_ent.construct(bs, -1, 1, False, prologue.class_bits, world) state = unpacker.unpack_baseline(prologue.recv_tables[cls]) state.update(diff) try: world.create(cls, index, serial, state) except AssertionError, e: # TODO: log here. pass
def stream(self, tick=0): match = self.index.match cb, rt = self.class_bits, self.recv_tables st = copy.deepcopy(self.string_tables) st_ib = st['instancebaseline'] full_packet_peeks = \ filter(lambda peek: peek.tick <= tick, match.full_packet_peeks) for peek in full_packet_peeks: full_packet = di.read(self.io, peek) for table in full_packet.string_table.tables: assert not table.items_clientside if table.table_name == 'ActiveModifiers': observer = o_am.construct() else: observer = None entries = [(i, e.str, e.data) for i, e in enumerate(table.items)] st[table.table_name].update_all(entries) full_packet = di.read(self.io, full_packet_peeks[-1]) p_io = io.BufferedReader(io.BytesIO(full_packet.packet.data)) index = pi.index(p_io) csvc_packet_entities = \ pi.read(p_io, index.find(pb_n.CSVCMsg_PacketEntities)) world = w.construct(rt) bitstream = bs.construct(csvc_packet_entities.entity_data) ct = csvc_packet_entities.updated_entries unpacker = uent.unpack(bitstream, -1, ct, False, cb, world) for index, mode, (cls, serial, diff) in unpacker: bitstream = bs.construct(st['instancebaseline'].get(cls)[1]) unpacker = uent.unpack(bitstream, -1, 1, False, cb, world) state = dict(unpacker.unpack_baseline(rt[cls])) state.update(diff) try: world.create(cls, index, serial, state) except AssertionError, e: print e
def stream(self, tick=0): match = self.index.match cb, rt = self.class_bits, self.recv_tables st = copy.deepcopy(self.string_tables) st_ib = st['instancebaseline'] full_packet_peeks = \ filter(lambda peek: peek.tick <= tick, match.full_packet_peeks) for peek in full_packet_peeks: full_packet = di.read(self.io, peek) for table in full_packet.string_table.tables: assert not table.items_clientside entries = [(i, e.str, e.data) for i, e in enumerate(table.items)] st[table.table_name].update_all(entries) full_packet = di.read(self.io, full_packet_peeks[-1]) p_io = io.BufferedReader(io.BytesIO(full_packet.packet.data)) index = pi.index(p_io) csvc_packet_entities = \ pi.read(p_io, index.find(pb_n.CSVCMsg_PacketEntities)) world = w.construct(rt) bitstream = bs.construct(csvc_packet_entities.entity_data) ct = csvc_packet_entities.updated_entries unpacker = uent.unpack(bitstream, -1, ct, False, cb, world) for index, mode, (cls, serial, diff) in unpacker: bitstream = bs.construct(st['instancebaseline'].get(cls)[1]) unpacker = uent.unpack(bitstream, -1, 1, False, cb, world) state = dict(unpacker.unpack_baseline(rt[cls])) state.update(diff) try: world.create(cls, index, serial, state) except AssertionError, e: print e
def reconstitute(full_packets, class_bits, recv_tables, string_tables): w = e_w.construct(recv_tables) st = string_tables st_mn = st['ModifierNames'] st_am = st['ActiveModifiers'] m = e_m.construct(st_mn, baseline=st_am) for _, fp in full_packets: for table in fp.string_table.tables: assert not table.items_clientside entries = [(_i, e.str, e.data) for _i, e in enumerate(table.items)] st[table.table_name].update_all(entries) if table.table_name == 'ActiveModifiers': m.reset() [m.note(e) for e in entries] if full_packets: _, fp = full_packets[-1] packet = ie_packet.construct(p_io.construct(fp.packet.data)) _, pe = packet.svc_packet_entities ct = pe.updated_entries bs = b_io.construct(pe.entity_data) unpacker = u_ent.construct(bs, -1, ct, False, class_bits, w) for index, mode, (cls, serial, diff) in unpacker: data = st['instancebaseline'].get(cls)[1] bs = b_io.construct(data) unpacker = u_ent.construct(bs, -1, 1, False, class_bits, w) state = unpacker.unpack_baseline(recv_tables[cls]) state.update(diff) w.create(cls, index, serial, state, dict(diff)) return w, m, st