示例#1
0
def test_vpk(f):
    assert f.endswith("_dir.vpk")
    prefix = f[0:-len("_dir.vpk")]

    v = VPK()
    with open(prefix + "_dir.vpk", "rb") as s:
        v.unpack(s)

    for ft in v["index"]:
        for p in ft["directory"]:
            for f in p["file"]:
                print("File {}/{}.{}".format(p["path"].data,
                                             f["filename"].data,
                                             ft["type"].data))
                if f["archive_index"].data == 0x7FFF:
                    archive_file = "{}_dir.vpk".format(prefix)
                    o = f["archive_offset"].data + v["index_size"].data + 12
                else:
                    archive_file = "{}_{:03}.vpk".format(
                        prefix, f["archive_index"].data)
                    o = f["archive_offset"].data
                n = f["archive_size"].data
                print("Archive {} offset {} size {}".format(
                    archive_file, o, n))
                with open(archive_file, "rb") as s:
                    s.seek(o)
                    d = s.read(n)
                    assert len(d) == n, (len(d), n)
                d = f["preload_data"].data + d
                my_crc = crc32(d) & 0xFFFFFFFF
                print("CRC {} = {}, {}".format(my_crc, f["crc"].data,
                                               my_crc == f["crc"].data))
示例#2
0
def test_vpk(f):
    assert f.endswith("_dir.vpk")
    prefix = f[0:-len("_dir.vpk")]

    v = VPK()
    with open(prefix+"_dir.vpk", "rb") as s:
        v.unpack(s)

    for ft in v["index"]:
        for p in ft["directory"]:
            for f in p["file"]:
                print("File {}/{}.{}".format(p["path"].data, f["filename"].data, ft["type"].data))
                if f["archive_index"].data == 0x7FFF:
                    archive_file = "{}_dir.vpk".format(prefix)
                    o = f["archive_offset"].data + v["index_size"].data + 12
                else:
                    archive_file = "{}_{:03}.vpk".format(prefix, f["archive_index"].data)
                    o = f["archive_offset"].data
                n = f["archive_size"].data
                print("Archive {} offset {} size {}".format(archive_file, o, n))
                with open(archive_file, "rb") as s:
                    s.seek(o)
                    d = s.read(n)
                    assert len(d) == n, (len(d), n)
                d = f["preload_data"].data + d
                my_crc = crc32(d) & 0xFFFFFFFF
                print("CRC {} = {}, {}".format(my_crc, f["crc"].data, my_crc == f["crc"].data))
示例#3
0
            dirs.append({
                "path": d,
                "file": files,
            })
        types.append({
            "type": t,
            "directory": dirs,
        })
    v = VPK()
    v.data = {
        "version": 1,
        "index_size": 0,
        "index": types,
    }
    with open("{}_dir.vpk".format(prefix), "wb") as s:
        v.pack(s)


if __name__ == "__main__":
    if argv[1] == "t":  # test
        test_vpk(argv[2])
    elif argv[1] == "j":  # json
        v = VPK()
        with open(argv[2], "rb") as s:
            v.unpack(s)
        print(dumps(v.serialize(), indent=4))
    elif argv[1] == "a":  # create a vpk file
        create_vpk(argv[2], argv[3])
    else:
        assert False, "wrong command line options"
示例#4
0
                    })
            dirs.append({
                "path": d,
                "file": files,
                })
        types.append({
            "type": t,
            "directory": dirs,
            })
    v = VPK()
    v.data = {
        "version": 1,
        "index_size": 0,
        "index": types,
        }
    with open("{}_dir.vpk".format(prefix), "wb") as s:
        v.pack(s)

if __name__ == "__main__":
    if argv[1] == "t": # test
        test_vpk(argv[2])
    elif argv[1] == "j": # json
        v = VPK()
        with open(argv[2], "rb") as s:
            v.unpack(s)
        print(dumps(v.serialize(), indent=4))
    elif argv[1] == "a": # create a vpk file
        create_vpk(argv[2], argv[3])
    else:
        assert False, "wrong command line options"