Exemplo n.º 1
0
def image_0x14(header_id, width, height, data):
    pixels = {}
    for y in range(height):
        for x in range(width):
            o = (y * width + x) * 3
            c1, c2, c3 = map(ord, data[o:o + 3])
            pixels[(x, y)] = (c3, c2, c1)
    png.output_png("surface/%08X_014.png" % header_id, width, height, pixels)
Exemplo n.º 2
0
def image_0x1C(header_id, width, height, data):
    pixels = {}
    for y in range(height):
        for x in range(width):
            o = (y * width + x)
            c = ord(data[o])
            pixels[(x, y)] = (c, c, c)
    png.output_png("surface/%08X_1C.png" % header_id, width, height, pixels)
Exemplo n.º 3
0
def image_0x15(header_id, width, height, data):
    pixels = {}
    apixels = {}
    for y in range(height):
        for x in range(width):
            o = (y * width + x) * 4
            c1, c2, c3, c4 = map(ord, data[o:o + 4])
            pixels[(x, y)] = (c3, c2, c1)
            apixels[(x, y)] = (c4, c4, c4)
    png.output_png("local/%08X_015.png" % header_id, width, height, pixels)
    png.output_png("local/%08X_015_a.png" % header_id, width, height, apixels)
Exemplo n.º 4
0
def image_0x31545844(header_id, width, height, data):
    pixels = {}
    
    lngth = width * height // 2
    for bb in range(lngth // 8):
        o = bb * 8
        blk = map(ord, data[o:o + 8])
        
        c0 = blk[1] * 256 + blk[0]
        c1 = blk[3] * 256 + blk[2]
        
        c0r, c0g, c0b = rgb565(c0)
        c1r, c1g, c1b = rgb565(c1)
        
        if c0 > c1:
            c2r = (2 * c0r + 1 * c1r) // 3
            c2g = (2 * c0g + 1 * c1g) // 3
            c2b = (2 * c0b + 1 * c1b) // 3
            c3r = (1 * c0r + 2 * c1r) // 3
            c3g = (1 * c0g + 2 * c1g) // 3
            c3b = (1 * c0b + 2 * c1b) // 3
        else:
            c2r = (1 * c0r + 1 * c1r) // 2
            c2g = (1 * c0g + 1 * c1g) // 2
            c2b = (1 * c0b + 1 * c1b) // 2
            c3r = 0  # @@@
            c3g = 0  # @@@
            c3b = 0  # @@@
        
        for i in range(4):
            for j in range(4):
                b = blk[4 + i]
                if j == 0:
                    b2 = (b // 1) % 4
                elif j == 1:
                    b2 = (b // 4) % 4
                elif j == 2:
                    b2 = (b // 16) % 4
                elif j == 3:
                    b2 = (b // 64) % 4
                
                x = (bb % (width // 4)) * 4 + j
                y = (bb // (width // 4)) * 4 + i
                
                if b2 == 0:
                    pixels[(x, y)] = c0r, c0g, c0b
                elif b2 == 1:
                    pixels[(x, y)] = c1r, c1g, c1b
                elif b2 == 2:
                    pixels[(x, y)] = c2r, c2g, c2b
                elif b2 == 3:
                    pixels[(x, y)] = c3r, c3g, c3b
    
    png.output_png("surface/%08X_DXT1.png" % header_id, width, height, pixels)
Exemplo n.º 5
0
def image_0x31545844(header_id, width, height, data):
    pixels = {}

    lngth = width * height // 2
    for bb in range(lngth // 8):
        o = bb * 8
        blk = map(ord, data[o:o + 8])

        c0 = blk[1] * 256 + blk[0]
        c1 = blk[3] * 256 + blk[2]

        c0r, c0g, c0b = rgb565(c0)
        c1r, c1g, c1b = rgb565(c1)

        if c0 > c1:
            c2r = (2 * c0r + 1 * c1r) // 3
            c2g = (2 * c0g + 1 * c1g) // 3
            c2b = (2 * c0b + 1 * c1b) // 3
            c3r = (1 * c0r + 2 * c1r) // 3
            c3g = (1 * c0g + 2 * c1g) // 3
            c3b = (1 * c0b + 2 * c1b) // 3
        else:
            c2r = (1 * c0r + 1 * c1r) // 2
            c2g = (1 * c0g + 1 * c1g) // 2
            c2b = (1 * c0b + 1 * c1b) // 2
            c3r = 0  # @@@
            c3g = 0  # @@@
            c3b = 0  # @@@

        for i in range(4):
            for j in range(4):
                b = blk[4 + i]
                if j == 0:
                    b2 = (b // 1) % 4
                elif j == 1:
                    b2 = (b // 4) % 4
                elif j == 2:
                    b2 = (b // 16) % 4
                elif j == 3:
                    b2 = (b // 64) % 4

                x = (bb % (width // 4)) * 4 + j
                y = (bb // (width // 4)) * 4 + i

                if b2 == 0:
                    pixels[(x, y)] = c0r, c0g, c0b
                elif b2 == 1:
                    pixels[(x, y)] = c1r, c1g, c1b
                elif b2 == 2:
                    pixels[(x, y)] = c2r, c2g, c2b
                elif b2 == 3:
                    pixels[(x, y)] = c3r, c3g, c3b

    png.output_png("surface/%08X_DXT1.png" % header_id, width, height, pixels)
Exemplo n.º 6
0
def image_0x15(header_id, width, height, data):
    pixels = {}
    apixels = {}
    for y in range(height):
        for x in range(width):
            o = (y * width + x) * 4
            c1, c2, c3, c4 = map(ord, data[o:o + 4])
            pixels[(x, y)] = (c3, c2, c1)
            apixels[(x, y)] = (c4, c4, c4)
    png.output_png("surface/%08X_015.png" % header_id, width, height, pixels)
    png.output_png("surface/%08X_015_a.png" % header_id, width, height,
                   apixels)
Exemplo n.º 7
0
def image_0x33545844(header_id, width, height, data):
    pixels = {}
      
    lngth = width * height
    for bb in range(lngth // 16):
        o = bb * 16
        # ignore alpha for now
        blk = map(ord, data[o + 8:o + 16])
        
        c0 = blk[1] * 256 + blk[0]
        c1 = blk[3] * 256 + blk[2]
        
        c0r, c0g, c0b = rgb565(c0)
        c1r, c1g, c1b = rgb565(c1)
        
        c2r = (2 * c0r + 1 * c1r) // 3
        c2g = (2 * c0g + 1 * c1g) // 3
        c2b = (2 * c0b + 1 * c1b) // 3
        c3r = (1 * c0r + 2 * c1r) // 3
        c3g = (1 * c0g + 2 * c1g) // 3
        c3b = (1 * c0b + 2 * c1b) // 3
        
        for i in range(4):
            for j in range(4):
                b = blk[4 + i]
                if j == 0:
                    b2 = (b // 1) % 4
                elif j == 1:
                    b2 = (b // 4) % 4
                elif j == 2:
                    b2 = (b // 16) % 4
                elif j == 3:
                    b2 = (b // 64) % 4
                
                x = (bb % (width // 4)) * 4 + j
                y = (bb // (width // 4)) * 4 + i
                
                if b2 == 0:
                    pixels[(x, y)] = c0r, c0g, c0b
                elif b2 == 1:
                    pixels[(x, y)] = c1r, c1g, c1b
                elif b2 == 2:
                    pixels[(x, y)] = c2r, c2g, c2b
                elif b2 == 3:
                    pixels[(x, y)] = c3r, c3g, c3b
      
    png.output_png("surface/%08X_DXT3.png" % header_id, width, height, pixels)
Exemplo n.º 8
0
def image_0x33545844(header_id, width, height, data):
    pixels = {}

    lngth = width * height
    for bb in range(lngth // 16):
        o = bb * 16
        # ignore alpha for now
        blk = map(ord, data[o + 8:o + 16])

        c0 = blk[1] * 256 + blk[0]
        c1 = blk[3] * 256 + blk[2]

        c0r, c0g, c0b = rgb565(c0)
        c1r, c1g, c1b = rgb565(c1)

        c2r = (2 * c0r + 1 * c1r) // 3
        c2g = (2 * c0g + 1 * c1g) // 3
        c2b = (2 * c0b + 1 * c1b) // 3
        c3r = (1 * c0r + 2 * c1r) // 3
        c3g = (1 * c0g + 2 * c1g) // 3
        c3b = (1 * c0b + 2 * c1b) // 3

        for i in range(4):
            for j in range(4):
                b = blk[4 + i]
                if j == 0:
                    b2 = (b // 1) % 4
                elif j == 1:
                    b2 = (b // 4) % 4
                elif j == 2:
                    b2 = (b // 16) % 4
                elif j == 3:
                    b2 = (b // 64) % 4

                x = (bb % (width // 4)) * 4 + j
                y = (bb // (width // 4)) * 4 + i

                if b2 == 0:
                    pixels[(x, y)] = c0r, c0g, c0b
                elif b2 == 1:
                    pixels[(x, y)] = c1r, c1g, c1b
                elif b2 == 2:
                    pixels[(x, y)] = c2r, c2g, c2b
                elif b2 == 3:
                    pixels[(x, y)] = c3r, c3g, c3b

    png.output_png("surface/%08X_DXT3.png" % header_id, width, height, pixels)
Exemplo n.º 9
0
def dump_cell_file(entry):
    j, unk1, file_id, offset, size1, timestamp, version, size2, unk2 = entry

    if 0x27010000 <= file_id <= 0x2701FFFF or 0x27020000 <= file_id <= 0x2702FFFF:
        pass
    elif 0x80210000 <= file_id <= 0x8021FFFF or 0x80220000 <= file_id <= 0x8022FFFF:
        pass
    elif 0x80410000 <= file_id <= 0x8041FFFF or 0x80420000 <= file_id <= 0x8042FFFF:
        pass
    elif 0x80510000 <= file_id <= 0x8051FFFF or 0x80520000 <= file_id <= 0x8052FFFF:
        pass
    elif 0x80010000 <= file_id <= 0x8001FFFF or 0x80020000 <= file_id <= 0x8002FFFF:
        # print "%08X %08X %08X %s %08X | %08X %08X %08X | %08X" % (file_id, offset, size1, time.ctime(timestamp), version, size2, unk1, unk2, size2 - size1)
        
        f.stream.seek(offset)
        
        j, k, l, m, n = struct.unpack("<LLLHH", f.stream.read(0x10))
        # print "%08X %08X %08X %04X %04X" % (j, k, l, m, n)
        
        assert k == 0
        
        if j == 0:
            if m == 0xDA78:
                # print "compressed"
                assert unk1 % 0x100 == 0x03
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[12:]
                content = zlib.decompress(data)
                assert l == len(content)
            else:
                # print "uncompressed"
                assert unk1 % 0x100 == 0x02
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[8:]
                content = data
            
            header_id, unk1, unk2, unk3 = struct.unpack("<LLLL", content[:0x10])
            print "%08X %08X %08X %08X" % (header_id, unk1, unk2, unk3)
            assert header_id == file_id
            if unk1 != 0:
                assert unk1 == 0x00200000 + header_id
            assert unk2 == 0x00000000
            assert unk3 == 0x00000441
            
            if len(content) == 0x1168:
                data = content[0x10:0x10 + (0x441 * 2)]
                pixels = {}
                for y in range(32):
                    for x in range(32):
                        o = (y * (33) + x) * 2
                        h = struct.unpack("<H", data[o:o + 2])[0]
                        c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                        pixels[(y, 32 - x - 1)] = (c, c, c)
                png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
            else:
                # @@@ just grab the first 0x441 * 2 anyway
                data = content[0x10:0x10 + (0x441 * 2)]
                pixels = {}
                for y in range(32):
                    for x in range(32):
                        o = (y * (33) + x) * 2
                        h = struct.unpack("<H", data[o:o + 2])[0]
                        c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                        pixels[(y, 32 - x - 1)] = (c, c, c)
                png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
        else:
            if m == 0xDA78:
                # print "compressed"
                assert unk1 % 0x100 == 0x03
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[12:]
                try:
                    content = zlib.decompress(data)
                except zlib.error:
                    return
                # assert l == len(content)
            else:
                # print "uncompressed"
                assert unk1 % 0x100 == 0x02
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[8:]
                content = data
            
            header_id, unk1, unk2, unk3 = struct.unpack("<LLLL", content[:0x10])
            print "%08X %08X %08X %08X" % (header_id, unk1, unk2, unk3)
            assert header_id == file_id
            if unk1 != 0:
                assert unk1 == 0x00200000 + header_id
            assert unk2 == 0x00000000
            assert unk3 == 0x00000441

            # @@@ just grab the first 0x441 * 2 anyway
            data = content[0x10:0x10 + (0x441 * 2)]
            if len(data) < 0x441 * 2:
                return
            pixels = {}
            for y in range(32):
                for x in range(32):
                    o = (y * (33) + x) * 2
                    h = struct.unpack("<H", data[o:o + 2])[0]
                    c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                    pixels[(y, 32 - x - 1)] = (c, c, c)
            png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
    else:
        print "%08X" % file_id
Exemplo n.º 10
0
SIZE = 7682

pixels = zeros((SIZE, SIZE, 3), dtype=uint8)

for y in range(64, SIZE - 32):
    for x in range(32, SIZE - 32):
# for y in range(1000, 2000):
#     for x in range(4500, 5500):
        cy, py = divmod(y, 30)
        cx, px = divmod(x, 30)
        file_id = 0x80020000 + cy * 0x100 + cx
        if file_id not in height_map:
            print "loading %08X" % file_id
            height_map[file_id] = heights(f.find_file(file_id))
            if height_map[file_id] is not None:
                print "calculating hillshade"
                hill_shade[file_id] = hillshade(height_map[file_id])
            else:
                hill_shade[file_id] = None
        if hill_shade[file_id] is not None:
            hs = hill_shade[file_id]
            hm = height_map[file_id]
            c = 128 - int(hs[py, px]) / 4
            r, g, b = [cc * (c / 255.) for cc in colour_for_height(hm[py, px])]
            pixels[y, SIZE - x] = (r, g, b)
#             height = hm[py][px]
#             pixels[y, SIZE - x] = colour_for_height(height)
print "outputing"
png.output_png("heights.png", SIZE, SIZE, pixels)
Exemplo n.º 11
0
def dump_cell_file(entry):
    j, unk1, file_id, offset, size1, timestamp, version, size2, unk2 = entry

    if 0x27010000 <= file_id <= 0x2701FFFF or 0x27020000 <= file_id <= 0x2702FFFF:
        pass
    elif 0x80210000 <= file_id <= 0x8021FFFF or 0x80220000 <= file_id <= 0x8022FFFF:
        pass
    elif 0x80410000 <= file_id <= 0x8041FFFF or 0x80420000 <= file_id <= 0x8042FFFF:
        pass
    elif 0x80510000 <= file_id <= 0x8051FFFF or 0x80520000 <= file_id <= 0x8052FFFF:
        pass
    elif 0x80010000 <= file_id <= 0x8001FFFF or 0x80020000 <= file_id <= 0x8002FFFF:
        # print "%08X %08X %08X %s %08X | %08X %08X %08X | %08X" % (file_id, offset, size1, time.ctime(timestamp), version, size2, unk1, unk2, size2 - size1)

        f.stream.seek(offset)

        j, k, l, m, n = struct.unpack("<LLLHH", f.stream.read(0x10))
        # print "%08X %08X %08X %04X %04X" % (j, k, l, m, n)

        assert k == 0

        if j == 0:
            if m == 0xDA78:
                # print "compressed"
                assert unk1 % 0x100 == 0x03
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[12:]
                content = zlib.decompress(data)
                assert l == len(content)
            else:
                # print "uncompressed"
                assert unk1 % 0x100 == 0x02
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[8:]
                content = data

            header_id, unk1, unk2, unk3 = struct.unpack(
                "<LLLL", content[:0x10])
            print "%08X %08X %08X %08X" % (header_id, unk1, unk2, unk3)
            assert header_id == file_id
            if unk1 != 0:
                assert unk1 == 0x00200000 + header_id
            assert unk2 == 0x00000000
            assert unk3 == 0x00000441

            if len(content) == 0x1168:
                data = content[0x10:0x10 + (0x441 * 2)]
                pixels = {}
                for y in range(32):
                    for x in range(32):
                        o = (y * (33) + x) * 2
                        h = struct.unpack("<H", data[o:o + 2])[0]
                        c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                        pixels[(y, 32 - x - 1)] = (c, c, c)
                png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
            else:
                # @@@ just grab the first 0x441 * 2 anyway
                data = content[0x10:0x10 + (0x441 * 2)]
                pixels = {}
                for y in range(32):
                    for x in range(32):
                        o = (y * (33) + x) * 2
                        h = struct.unpack("<H", data[o:o + 2])[0]
                        c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                        pixels[(y, 32 - x - 1)] = (c, c, c)
                png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
        else:
            if m == 0xDA78:
                # print "compressed"
                assert unk1 % 0x100 == 0x03
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[12:]
                try:
                    content = zlib.decompress(data)
                except zlib.error:
                    return
                # assert l == len(content)
            else:
                # print "uncompressed"
                assert unk1 % 0x100 == 0x02
                f.stream.seek(offset)
                data = f.stream.read(size1 + 0x08)[8:]
                content = data

            header_id, unk1, unk2, unk3 = struct.unpack(
                "<LLLL", content[:0x10])
            print "%08X %08X %08X %08X" % (header_id, unk1, unk2, unk3)
            assert header_id == file_id
            if unk1 != 0:
                assert unk1 == 0x00200000 + header_id
            assert unk2 == 0x00000000
            assert unk3 == 0x00000441

            # @@@ just grab the first 0x441 * 2 anyway
            data = content[0x10:0x10 + (0x441 * 2)]
            if len(data) < 0x441 * 2:
                return
            pixels = {}
            for y in range(32):
                for x in range(32):
                    o = (y * (33) + x) * 2
                    h = struct.unpack("<H", data[o:o + 2])[0]
                    c = int(math.log(((16 * h) % 65535) + 1, 1.045))
                    pixels[(y, 32 - x - 1)] = (c, c, c)
            png.output_png("cells/%08X.png" % file_id, 32, 32, pixels)
    else:
        print "%08X" % file_id
Exemplo n.º 12
0
SIZE = 7682

pixels = zeros((SIZE, SIZE, 3), dtype=uint8)

# for y in range(1000, 2000):
#     for x in range(4500, 5500):

for y in range(64, SIZE - 32):
    for x in range(32, SIZE - 32):
        cy, py = divmod(y, 30)
        cx, px = divmod(x, 30)
        file_id = 0x80020000 + cy * 0x100 + cx
        if file_id not in height_map:
            print "loading %08X" % file_id
            height_map[file_id] = heights(f.find_file(file_id))
            if height_map[file_id] is not None:
                print "calculating hillshade"
                hill_shade[file_id] = hillshade(height_map[file_id])
            else:
                hill_shade[file_id] = None
        if hill_shade[file_id] is not None:
            hs = hill_shade[file_id]
            hm = height_map[file_id]
            c = 128 - int(hs[py, px]) / 4
            r, g, b = [cc * (c / 255.) for cc in colour_for_height(hm[py, px])]
            pixels[y, SIZE - x] = (r, g, b)
#             height = hm[py][px]
#             pixels[y, SIZE - x] = colour_for_height(height)
print "outputing"
png.output_png("heights.png", SIZE, SIZE, pixels)