Ejemplo n.º 1
0
def downloadLevel(id: int) -> Tuple[LevelString, RobDict]:
    postdata = {'levelID': id, 'gameVersion': gameV, 'secret': secret}
    downloaded = httpRequest.postRequest(url, postdata)
    levelInfo = levelUtil.parseKeyVarArray(downloaded.decode(), ':')
    levelString = LevelString(saveUtil.decodeLevel(levelInfo['4']))

    return levelString, levelInfo
Ejemplo n.º 2
0
def convLevelString(string: LevelString) -> LevelString:
    '''
    converts a 2.1 level string to 1.9 format
    - expects level string
    - returns level string
    '''

    levelObjects = string.decode().split(';')
    levelHeader = levelObjects.pop(0)

    splitHeader = levelHeader.split(',')
    if 'kS38' in levelHeader:
        splitHeader[1] = convertColorHeader(','.join(splitHeader[:2]))
        splitHeader.pop(0)
    newHeader = ','.join(splitHeader)

    newColors = convertColors(';'.join(levelObjects))

    return LevelString((newHeader + ';' + newColors).encode())
Ejemplo n.º 3
0
def decodeLevel(string: str) -> LevelString:
    # hacky way to check if the string is already decoded
    if string.startswith("kS"):
        return LevelString(string.encode())

    try:
        decoded = base64.urlsafe_b64decode(string)
    except BaseException:
        # string is either invalid or already decoded
        if string.startswith("kS"):
            return LevelString(string.encode())
        else:
            raise Exception()
    try:
        decompressed = gzip.decompress(decoded)  # bug on 2.1  idk...?
    except BaseException:
        decompressed = zlib.decompress(decoded, zlib.MAX_WBITS)
        #  1.9 handling except if this errors then :p
    # i also just remembered i have no idea how i found out about this lol
    return LevelString(decompressed)
def uploadLevel(levelString: LevelString,
                levelInfo: RobDict,
                originalID: int = None,
                accUsername: str = username,
                password: str = None,
                unlisted: bool = True) -> int:
    """
    Uploads a level to 1.9 servers
    """

    # 1.9 descriptions aren't base64 encoded, we need to remove illegal
    # characters before upload breaks them anyways
    desc: str = levelInfo["3"]
    if (gameVersion < 20):
        desc = base64.urlsafe_b64decode(desc).decode()
        desc = re.sub(r"[^A-Za-z0-9\., \$\-\_\.\+\!\*\'()]", "",
                      desc)  # remove anything not url safe

    # some params don't exist
    postdata = {
        "gjp":
        '',
        "gameVersion":
        gameVersion,
        "binaryVersion":
        gameVersion + 14,  # definitely not the correct way
        "udid":
        "S-hi-people",
        "uuid":
        3109282,
        "userName":
        accUsername,
        "unlisted":
        unlisted,
        "levelDesc":
        desc,
        "levelName":
        levelInfo["2"],
        "levelVersion":
        levelInfo["5"],
        "levelLength":
        levelInfo["15"],
        "audioTrack":
        levelInfo["12"],
        "password":
        1,
        "levelID":
        0,
        "original":
        levelInfo["1"],
        "songID":
        levelInfo.get("35", 0),
        "objects":
        levelInfo.get("45", 0),
        "seed2":
        base64.urlsafe_b64encode(robtopCrypto.makeSeed(levelString).encode()),
        "wt2":
        0,
        "wt":
        3,
        "seed":
        "PJsBAJ24Po",
        "extraString": ('_'.join(map(str, (0 for _ in range(55))))),
        "levelInfo":
        saveUtil.encodeLevel(LevelString(b"0;1;1.12;;422.00;;")),
        # thank nekit
        "auto":
        levelInfo.get("25", 0),
        "twoPlayer":
        0,  # going to guess
        "ldm":
        levelInfo.get("40", 0),
        "coins":
        levelInfo.get("37", 0),
        "requestedStars":
        levelInfo.get("39", 0),
        "gdw":
        0,
        "secret":
        "Wmfd2893gb7"
    }
    postdata["levelString"] = levelString

    if gameVersion >= 20:
        if not password or not accUsername:
            raise ArgumentError(None, "invalid credentials!")
        try:
            accID: int = robtopCrypto.loginUser(accUsername, password)[0]
        except BaseException:
            print("invalid login")
            raise Exception()
        postdata["gjp"] = robtopCrypto.getGJP(password)
        postdata["accountID"] = accID
        postdata["userName"] = robtopCrypto.getUsername(accID)

    uploadRequest = httpRequest.postRequest(url, postdata)

    try:
        levelID: int = int(uploadRequest)
        if levelID == -1:  # -1 is an error dumb
            raise Exception()
        return levelID
    except BaseException:
        print(f"Error occured while reuploading:\n{uploadRequest}")
        raise Exception()
        help="convert unlined clubstep blocks 1-8 to those with lines",
        action="store_true")
    parser.add_argument("--glow",
                        help="convert full glow blocks to 1.9 equivalents",
                        action="store_true")
    parser.add_argument(
        "--color",
        help="convert colored blocks to non colored 1.9 equivalents",
        action="store_true")
    parser.add_argument("--song", help="set custom song id", type=int)

    args = parser.parse_args()

    mainID = args.id

    levelString: LevelString = LevelString(b"")
    levelInfo: RobDict = RobDict({})

    try:
        levelString, levelInfo = levelDownloader.downloadLevel(mainID)
    except BaseException:
        print("invalid level!")
        sys.exit()

    print(f"Downloaded level `{levelInfo['2']}`")
    if args.club:
        print("""Clubstep block conversion enabled!
This can make some levels impossible!""")
        levelUtil.convClubstep = True
    if args.color:
        print("""Color block conversion enabled!
Ejemplo n.º 6
0
if __name__ == "__main__":
    print("~ 1.9 Level Reuploader by zmx ~")

    mainID: int = 128
    try:
        mainID = int(sys.argv[1])
    except BaseException:
        print(f"""Usage: {sys.argv[0]} <id> [audio id]""")
        sys.exit()

    # download level first
    levelDownloader.url = "https://absolllute.com/gdps/\
gdapi/downloadGJLevel19.php"

    levelString: LevelString = LevelString(b"")
    levelInfo: RobDict = RobDict({})

    try:
        levelString, levelInfo = levelDownloader.downloadLevel(mainID)
    except BaseException:
        print("invalid level!")
        sys.exit()

    print(f"Downloaded level `{levelInfo['2']}`")

    # check 1.9 acc data
    robtopCrypto.loginURL = "https://absolllute.com/gdps/gdapi\
/accounts/loginGJAccount.php"

    accUsername: str = input("1.9 Username: ")
def getObjCount(levelString: LevelString) -> int:
    """
    Gets object count for a level
    """
    objects = levelString.split(b';')
    return len(objects[1:-1])
    allow_collisions = False
    if args.allow_collisions:
        print("collisions enabled!")
        allow_collisions = True

    for pos, objects in enumerate(levels[1:]):
        print(f"Merging level {pos + 2} to level 1")
        if args.allow_collisions:
            finalLevel = listMerge(finalLevel, objects[:-1],
                                   not allow_collisions)
        # last object is ;, keep that outta here

    print(f"Final Object Count: {len(finalLevel)}")

    finalLevelStr: LevelString = LevelString(
        (levelHeader + ";" + (';').join(finalLevel) + ";").encode())
    finalLevelStr = LevelString(saveUtil.encodeLevel(finalLevelStr))

    levelInfo["2"] = incrementName(levelInfo["2"])
    levelInfo["45"] = str(getObjCount(finalLevelStr))

    if args.export:
        print("Exporting level...")
        with open(levelInfo['2'] + '.txt', 'w') as lvlFile:
            lvlFile.write(finalLevelStr)
        sys.exit()

    if levelConverter.gameVersion >= 20:
        import getpass
        accUsername: str = input("Username: "******"User password: ")