Exemplo n.º 1
0
def loadRegionFromArchive(archivePath, code):
    result = {}
    result["region"] = code
    with open(os.path.join(archivePath, code, "country_LZ.bin"), 'rb') as file:
        decompressedData = decompressFile(file)
        decompressed = io.BytesIO(decompressedData)
        for section in range(2):
            entryCount, = struct.unpack('<I', decompressed.read(4))
            entryList = result["countries" if section ==
                               0 else "countriesPatch"] = [
                                   {} for x in range(entryCount)
                               ]
            for entry in range(entryCount):
                entryResult = entryList[entry]
                p0, p1, p2, countryId = struct.unpack('BBBB',
                                                      decompressed.read(4))
                assert p0 == 0
                assert p1 == 0
                assert p2 == 0
                entryResult['country'] = countryId

                divisionCount, = struct.unpack('<I', decompressed.read(4))
                entryResult['divisionCount'] = divisionCount

                what, = struct.unpack('<I', decompressed.read(4))
                assert what == 0

                entryResult["name"] = parseName(decompressed)
                entryResult["sort"] = parseSort(decompressed)

                zeros = decompressed.read(0x20)
                assert zeros == b'\x00' * 0x20

        countries = result["countries"]
        for i in range(len(countries)):
            sort = parseSort(decompressed)
            assert countries[i]["sort"] == sort

        tailLen = len(countries) // 32 + 1
        tail = [
            struct.unpack('<I', decompressed.read(4))[0]
            for _ in range(tailLen)
        ]
        assert len(decompressed.read()) == 0
        for i in range(len(countries)):
            countries[i]["eshopLock"] = ((tail[i // 32] >> (i % 32)) & 1) == 1

        return result
Exemplo n.º 2
0
def loadCountryFromArchive(archivePath, code):
    result = {}
    result["code"] = code
    regions = ["CN", "EU", "JP", "KR", "TW", "US"]
    for regionCandidate in regions:
        path = os.path.join(archivePath, regionCandidate,
                            "{}_LZ.bin".format(code))
        if os.path.exists(path):
            result["region"] = regionCandidate
            break
    else:
        return
    with open(path, 'rb') as file:
        decompressedData = decompressFile(file)
        decompressed = io.BytesIO(decompressedData)

        for section in range(2):
            entryCount, = struct.unpack("<I", decompressed.read(4))
            if section == 0:
                entryCount += 1
            entryList = result["divisions" if section ==
                               0 else "divisionsPatch"] = [
                                   {} for x in range(entryCount)
                               ]
            for entry in range(entryCount):
                entryResult = entryList[entry]
                p0, p1, division, country = struct.unpack(
                    'BBBB', decompressed.read(4))
                entryResult["division"] = division
                assert country == code
                assert p0 == 0
                assert p1 == 0

                entryResult["name"] = parseName(decompressed)
                entryResult["sort"] = parseSort(decompressed)
                latitude, longitude = struct.unpack('<HH',
                                                    decompressed.read(4))
                entryResult["latitude"] = latitude
                entryResult["longitude"] = longitude

        divisios = result["divisions"]
        for i in range(len(divisios)):
            divisios[i]["sortPatch"] = parseSort(decompressed)

        result["tail"] = " ".join(
            ["{:02X}".format(x) for x in decompressed.read()])
        return result
Exemplo n.º 3
0
def loadRegionFromArchive(archivePath, code):
    result = {}
    result["region"] = code
    with open(os.path.join(archivePath, code, "country_LZ.bin"), 'rb') as file:
        decompressedData = decompressFile(file)
        decompressed = io.BytesIO(decompressedData)
        for section in range(2):
            entryCount, = struct.unpack('<I', decompressed.read(4))
            entryList = result["countries" if section ==
                               0 else "countriesPatch"] = [
                                   {} for x in range(entryCount)
                               ]
            for entry in range(entryCount):
                entryResult = entryList[entry]
                p0, p1, p2, countryId = struct.unpack('BBBB',
                                                      decompressed.read(4))
                assert p0 == 0
                assert p1 == 0
                assert p2 == 0
                entryResult['country'] = countryId

                divisionCount, = struct.unpack('<I', decompressed.read(4))
                entryResult['divisionCount'] = divisionCount

                what, = struct.unpack('<I', decompressed.read(4))
                assert what == 0

                entryResult["name"] = parseName(decompressed)
                entryResult["sort"] = parseSort(decompressed)

                zeros = decompressed.read(0x20)
                assert zeros == b'\x00' * 0x20

        countries = result["countries"]
        for i in range(len(countries)):
            sort = parseSort(decompressed)
            assert countries[i]["sort"] == sort

        result["tail"] = " ".join(
            ["{:02X}".format(x) for x in decompressed.read()])
        return result