Ejemplo n.º 1
0
def convert_qmo(data, path):
    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

    blocks = data.get_dict()

    min_z = max_z = None
    for pos in blocks.keys():
        x, y, z = pos
        if min_z is None:
            min_z = max_z = z
        min_z = min(min_z, z)
        max_z = max(max_z, z)

    qmo_model.y_size = max_z - min_z + 1

    for pos, color in blocks.items():
        x, y, z = switch_axes(*pos)
        y -= min_z
        qmo_model.blocks[(x, y, z)] = color

    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    open(path, 'wb').write(writer.get())
Ejemplo n.º 2
0
    def write(self, writer):
        data = ByteWriter()
        write_list(data, self.block_actions)
        write_list(data, self.player_hits)
        write_list(data, self.particles)
        write_list(data, self.sound_actions)
        write_list(data, self.shoot_actions)
        write_list(data, self.static_entities)
        write_list(data, self.chunk_items)

        data.write_uint32(len(self.items_8))
        for item in self.items_8:
            something, sub_items = item
            data.write_uint64(something)
            data.write_uint32(len(sub_items))
            for item in sub_items:
                data.write(item)

        write_list(data, self.pickups)
        write_list(data, self.kill_actions)
        write_list(data, self.damage_actions)
        write_list(data, self.passive_actions)

        write_list(data, self.missions)

        compressed_data = zlib.compress(data.get())
        writer.write_uint32(len(compressed_data))
        writer.write(compressed_data)
Ejemplo n.º 3
0
 def set_entity(self, entity, entity_id, mask=None):
     if mask is None:
         mask = FULL_MASK
     writer = ByteWriter()
     writer.write_uint64(entity_id)
     write_masked_data(entity, writer, mask)
     self.data = writer.get()
Ejemplo n.º 4
0
 def set_entity(self, entity, entity_id, mask=None):
     if mask is None:
         mask = FULL_MASK
     writer = ByteWriter()
     writer.write_uint64(entity_id)
     write_masked_data(entity, writer, mask)
     self.data = writer.get()
Ejemplo n.º 5
0
def convert_qmo(data, path):
    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

    blocks = data.get_dict()

    min_z = max_z = None
    for pos in blocks.keys():
        x, y, z = pos
        if min_z is None:
            min_z = max_z = z
        min_z = min(min_z, z)
        max_z = max(max_z, z)

    qmo_model.y_size = max_z - min_z + 1

    for pos, color in blocks.items():
        x, y, z = switch_axes(*pos)
        y -= min_z
        qmo_model.blocks[(x, y, z)] = color

    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    open(path, 'wb').write(writer.get())
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def to_cub(in_file, out_file):
    qmo_file = QubicleFile(ByteReader(open(in_file, "rb").read()))
    qmo_model = qmo_file.models[0]
    cub = CubModel()
    x_size, y_size, z_size = switch_axes(qmo_model.x_size, qmo_model.y_size, qmo_model.z_size)
    cub.x_size = x_size
    cub.y_size = y_size
    cub.z_size = z_size
    for k, v in qmo_model.blocks.items():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        cub.blocks[x2, y2, z2] = v
    writer = ByteWriter()
    cub.write(writer)
    with open(out_file, "wb") as fp:
        fp.write(writer.get())
Ejemplo n.º 8
0
def to_cub(in_file, out_file):
    qmo_file = QubicleFile(ByteReader(open(in_file, 'rb').read()))
    qmo_model = qmo_file.models[0]
    cub = CubModel()
    x_size, y_size, z_size = switch_axes(qmo_model.x_size, qmo_model.y_size,
                                         qmo_model.z_size)
    cub.x_size = x_size
    cub.y_size = y_size
    cub.z_size = z_size
    for k, v in qmo_model.blocks.items():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        cub.blocks[x2, y2, z2] = v
    writer = ByteWriter()
    cub.write(writer)
    with open(out_file, 'wb') as fp:
        fp.write(writer.get())
Ejemplo n.º 9
0
def to_qmo(in_file, out_file):
    cub = CubModel(ByteReader(open(in_file, "rb").read()))
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = switch_axes(cub.x_size, cub.y_size, cub.z_size)
    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
    for k, v in cub.blocks.items():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        qmo_model.blocks[x2, y2, z2] = v
    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    with open(out_file, "wb") as fp:
        fp.write(writer.get())
Ejemplo n.º 10
0
def to_qmo(in_file, out_file):
    cub = CubModel(ByteReader(open(in_file, 'rb').read()))
    qmo_file = QubicleFile()
    qmo_model = QubicleModel()
    x_size, y_size, z_size = switch_axes(cub.x_size, cub.y_size, cub.z_size)
    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
    for k, v in cub.blocks.items():
        x, y, z = k
        x2, y2, z2 = switch_axes(x, y, z)
        qmo_model.blocks[x2, y2, z2] = v
    qmo_file.models.append(qmo_model)
    writer = ByteWriter()
    qmo_file.write(writer)
    with open(out_file, 'wb') as fp:
        fp.write(writer.get())
Ejemplo n.º 11
0
    def write_debug(self):
        if self.debug_fp is None:
            return
        writer = ByteWriter()
        writer.write_uint32(len(self.entities))
        for entity in self.entities.values():
            writer.write_uint8(int(entity.is_tgen))
            entity.write(writer)

        self.debug_fp.write(writer.get())
Ejemplo n.º 12
0
    def write_debug(self):
        if self.debug_fp is None:
            return
        writer = ByteWriter()
        writer.write_uint32(len(self.entities))
        for entity in self.entities.values():
            writer.write_uint8(int(entity.is_tgen))
            entity.write(writer)

        self.debug_fp.write(writer.get())
Ejemplo n.º 13
0
def write_packet(packet):
    writer = ByteWriter()
    writer.write_uint32(packet.packet_id)
    packet.write(writer)
    return writer.get()
Ejemplo n.º 14
0
    def write(self, writer):
        data = ByteWriter()
        write_list(data, self.block_actions)
        write_list(data, self.player_hits)
        write_list(data, self.particles)
        write_list(data, self.sound_actions)
        write_list(data, self.shoot_actions)
        write_list(data, self.static_entities)
        write_list(data, self.chunk_items)

        data.write_uint32(len(self.items_8))
        for item in self.items_8:
            something, sub_items = item
            data.write_uint64(something)
            data.write_uint32(len(sub_items))
            for item in sub_items:
                data.write(item)

        write_list(data, self.pickups)
        write_list(data, self.kill_actions)
        write_list(data, self.damage_actions)
        write_list(data, self.passive_actions)

        write_list(data, self.missions)

        compressed_data = zlib.compress(data.get())
        writer.write_uint32(len(compressed_data))
        writer.write(compressed_data)
Ejemplo n.º 15
0
def write_packet(packet):
    writer = ByteWriter()
    writer.write_uint32(packet.packet_id)
    packet.write(writer)
    return writer.get()
Ejemplo n.º 16
0
    def write(self, writer):
        data = ByteWriter()

        write_list(data, self.items_1)
        write_list(data, self.player_hits)

        data.write_uint32(len(self.items_3))
        for item in self.items_3:
            data.write(item)

        write_list(data, self.sound_actions)
        write_list(data, self.shoot_actions)

        data.write_uint32(len(self.items_6))
        for item in self.items_6:
            data.write(item)

        write_list(data, self.chunk_items)

        data.write_uint32(len(self.items_8))
        for item in self.items_8:
            something, sub_items = item
            data.write_uint64(something)
            data.write_uint32(len(sub_items))
            for item in sub_items:
                data.write(item)

        write_list(data, self.pickups)
        write_list(data, self.kill_actions)
        write_list(data, self.damage_actions)

        data.write_uint32(len(self.items_12))
        for item in self.items_12:
            data.write(item)

        write_list(data, self.items_13)

        compressed_data = zlib.compress(data.get())
        writer.write_uint32(len(compressed_data))
        writer.write(compressed_data)
Ejemplo n.º 17
0
 def set_entity(self, entity, entity_id):
     writer = ByteWriter()
     writer.write_uint64(entity_id)
     write_masked_data(entity, writer)
     self.data = writer.get()