Example #1
0
def randomize_battle_animations():
    raise NotImplementedError
    pointers = [1, 2, 7, 0xa, 0xb, 0xc, 0xd]
    pointers = [p + 0xd4000 for p in pointers]
    short = [0, 3, 8, 0xa, 0xc]
    longg = [2, 4, 6]
    special = [0xd, 33]
    restricted = [6]
    f = open(get_outfile(), "r+b")
    for p in pointers:
        if random.choice([True, False]):
            continue
        f.seek(p)
        value = ord(f.read(1))
        container = [l for l in [short, longg] if value in l][0]
        notcontainer = [l for l in [short, longg] if l is not container][0]
        if random.randint(1, 100) == 100:
            # use special
            value = random.choice(special)
        elif random.choice([True, False]):
            # use same type
            value = random.choice(container)
        else:
            # use different type
            candidates = [v for v in notcontainer if v not in restricted]
            value = random.choice(candidates)
        f.seek(p)
        f.write(chr(value))
    f.close()
def randomize_rng(address=0xFE00):
    numbers = range(0x100)
    random.shuffle(numbers)
    f = open(get_outfile(), 'r+b')
    f.seek(address)
    f.write("".join([chr(n) for n in numbers]))
    f.close()
Example #3
0
def get_text(pointer):
    label = get_global_label()
    f = open(get_outfile(), "r+b")
    f.seek(pointer)
    s = ""
    while True:
        peek = f.read(1)
        if label == "AOS_NA" and ord(peek) == 1:
            break
        elif ord(peek) == 0xF0:
            pointer = f.tell()
            peek2 = f.read(1)
            if ord(peek2) == 0:
                break
            f.seek(pointer)
        s += peek
    if label == "AOS_NA":
        trim = [chr(0), chr(6), chr(0xa)]
    else:
        s = s.lstrip(chr(0))
        trim = [chr(0), chr(0xa)]
    while s[-1] in trim:
        for c in trim:
            s = s.rstrip(c)
    pointer = f.tell()
    f.close()
    return s, pointer
def randomize_battle_animations():
    raise NotImplementedError
    pointers = [1, 2, 7, 0xa, 0xb, 0xc, 0xd]
    pointers = [p + 0xd4000 for p in pointers]
    short = [0, 3, 8, 0xa, 0xc]
    longg = [2, 4, 6]
    special = [0xd, 33]
    restricted = [6]
    f = open(get_outfile(), "r+b")
    for p in pointers:
        if random.choice([True, False]):
            continue
        f.seek(p)
        value = ord(f.read(1))
        container = [l for l in [short, longg] if value in l][0]
        notcontainer = [l for l in [short, longg] if l is not container][0]
        if random.randint(1, 100) == 100:
            # use special
            value = random.choice(special)
        elif random.choice([True, False]):
            # use same type
            value = random.choice(container)
        else:
            # use different type
            candidates = [v for v in notcontainer if v not in restricted]
            value = random.choice(candidates)
        f.seek(p)
        f.write(chr(value))
    f.close()
Example #5
0
def randomize_rng(address=0xFE00):
    numbers = range(0x100)
    random.shuffle(numbers)
    f = open(get_outfile(), 'r+b')
    f.seek(address)
    f.write("".join([chr(n) for n in numbers]))
    f.close()
Example #6
0
def randomize_crystal_shards():
    if "y" not in get_flags():
        return

    FREELANCER, MIME = 0x84fc3, 0x91baf

    def map_crystal_job(value):
        return (7-(value%8)) + ((value/8)*8)

    def map_job_crystal(value):
        crystals = [c for c in range(24) if map_crystal_job(c) == value]
        assert len(crystals) == 1
        return crystals[0]

    values = []
    # galuf has no mime sprite
    addrs = [a for a in CRYSTAL_ADDRS if a not in [FREELANCER, MIME]]
    assert len(addrs) == 20
    f = open(get_outfile(), "r+b")
    start_candidates = [j.index for j in JobCommandObject.every
                        if j.commands[0] == 5 and j.index < 20]
    start_choice = random.choice(start_candidates)
    f.seek(FREELANCER)
    f.write(chr(map_job_crystal(start_choice)))
    remaining = [j.index for j in JobCommandObject.every
                 if j.index != 20 and j.index != start_choice]
    random.shuffle(remaining)
    assert len(addrs) == len(remaining) == 20
    for addr, j in zip(addrs, remaining):
        f.seek(addr)
        f.write(chr(map_job_crystal(j)))
    f.close()
    return values
Example #7
0
def rewrite_title_screen():
    title_len_1, title_len_2 = 17, 20
    s1 = 'v{0} SN {1}'.format(VERSION, get_seed())

    if any(hasattr(o, 'custom_random_degree') for o in ALL_OBJECTS):
        random_degree = 'CUSTOM'
    else:
        random_degree = round(get_random_degree() ** 0.5, 2)
    s2 = '{0} {1}'.format(random_degree, get_flags())

    s1 = s1.strip()
    s2 = s2.strip()
    assert len(s1) <= title_len_1
    assert len(s2) <= title_len_2
    while len(s1) < title_len_1:
        s1 = ' {0} '.format(s1)
    s1 = s1[:title_len_1]
    while len(s2) < title_len_2:
        s2 = ' {0} '.format(s2)
    s2 = s2[:title_len_2]
    assert len(s1) == title_len_1
    assert len(s2) == title_len_2

    f = open(get_outfile(), 'r+b')
    f.seek(addresses.title_text_1)
    f.write(NameMixin.encode(s1))
    f.seek(addresses.title_text_2)
    f.write(NameMixin.encode(s2))
    f.close()
Example #8
0
def randomize_file_select():
    if get_global_label() == "SMRPG_NA":
        addresses = [0x34757, 0x3489a, 0x34ee7, 0x340aa, 0x3501e]
    elif get_global_label() == "SMRPG_JP":
        addresses = [0x347d7, 0x3490d, 0x34f59, 0x340fa, 0x35099]
    else:
        return
    choices = {"peach": range(7, 13),
               "bowser": range(13, 19),
               "mallow": range(19, 25),
               "geno": range(25, 31),
               }
    values = random.choice(choices.values())
    values = [values[i] for i in [0, 1, 0, 0, 1]]
    f = open(get_outfile(), "r+b")
    for addr, value in zip(addresses, values):
        f.seek(addr)
        f.write(chr(value))

    if get_global_label() != "SMRPG_NA":
        return
    f.seek(0x3EF140)
    seed = str(get_seed()).center(10)
    f.write(seed)
    f.close()
Example #9
0
 def every(cls):
     if hasattr(cls, "_every"):
         return cls._every
     cls._every = super(JobAbilityObject, cls).every
     mimic = JobAbilityObject(get_outfile(), 0x115429, index=99,
                              groupindex=20)
     cls._every.append(mimic)
     return cls.every
Example #10
0
def randomize_rng():
    filename = get_outfile()
    f = open(filename, "r+b")
    f.seek(0xFEC0)
    random_numbers = range(0x100)
    random.shuffle(random_numbers)
    f.write("".join(map(chr, random_numbers)))
    f.close()
Example #11
0
 def every(cls):
     if hasattr(cls, "_every"):
         return cls._every
     cls._every = super(JobAbilityObject, cls).every
     mimic = JobAbilityObject(get_outfile(),
                              addresses.mime_abilities,
                              index=len(JobAbilityObject.every),
                              groupindex=max(JobAbilityObject.groups) + 1)
     cls._every.append(mimic)
     return cls.every
Example #12
0
 def vram_value(self):
     if hasattr(self, "_vram_value"):
         return self._vram_value
     anim_index = EnemSpriteObject.get(self.index).animation
     ptr = AnimSeqPTRObject.get(anim_index).anim_seq_ptr & 0x3fffff
     f = open(get_outfile(), "r+b")
     f.seek(ptr + 8)
     self._vram_value = ord(f.read(1))
     f.close()
     return self.vram_value
Example #13
0
def enable_cutscene_skip():
    # 0x1AF8 is the byte in SRAM that saves whether the game has been beaten
    # (#03 if so) and therefore cutscenes can be skipped.
    # This byte is copied to 02000060 when the game is turned on.
    # When Start is pressed during a cutscene, the byte is loaded from
    # memory at 0x5B56C.
    # This patch changes it to a simple MOV r0, #03 instruction.
    f = open(get_outfile(), "r+b")
    f.seek(addresses.cutscene_skip)
    f.write("".join(map(chr, [0x03, 0x20])))
    f.close()
Example #14
0
def write_seed_display():
    f = open(get_outfile(), "r+b")
    f.seek(addresses.start_game_text)
    s = "%s" % get_seed()
    while len(s) < 11:
        s += " "
    s = s[:11]
    f.write(s)
    f.seek(addresses.soul_set_text)
    s = ("%s-%s" % (VERSION, get_seed())) + chr(0x06)
    s += get_flags() + " " + " ".join(get_activated_codes())
    while len(s) < 26:
        s += " "
    s = s[:26].upper()
    f.write(s)
    f.close()
Example #15
0
     ALL_OBJECTS = [
         g for g in globals().values() if isinstance(g, type)
         and issubclass(g, TableObject) and g not in [TableObject]
     ]
     run_interface(ALL_OBJECTS, snes=True)
     if get_global_label() == "FFMQ_NA_1.1":
         DemoPlay = CharacterObject.get(0)
         DemoPlay.name_text = [texttable[c] for c in "Abyssnym"]
         while len(DemoPlay.name_text) < 16:
             DemoPlay.name_text += [0x03]
     hexify = lambda x: "{0:0>2}".format("%x" % x)
     numify = lambda x: "{0: >3}".format(x)
     minmax = lambda x: (min(x), max(x))
     clean_and_write(ALL_OBJECTS)
     if get_global_label() == "FFMQ_NA_1.1":
         write_title_screen(get_outfile(), get_seed(), get_flags())
         enemy_jump = 0xef8e
     elif get_global_label() == "FFMQ_JP":
         enemy_jump = 0xef92
     x = raw_input("Do you want to give Benjamin the power "
                   "to jump over enemies? (y/n) ")
     if x and x[0].lower() == 'y':
         f = open(get_outfile(), "r+b")
         f.seek(enemy_jump)
         f.write(chr(0x80))
         f.close()
     rewrite_snes_meta("FFMQ-R", VERSION, megabits=24, lorom=True)
     finish_interface()
 except Exception, e:
     print "ERROR: %s" % e
     raw_input("Press Enter to close this program.")
Example #16
0
    def randomize_all(cls):
        f = open(get_outfile(), "r+b")
        f.seek(addresses.hammer3)
        num_items = ord(f.read(1))
        indexes = map(ord, f.read(num_items))
        f.close()
        sios = [ShopIndexObject.get(i) for i in indexes]
        hard_mode = "chaos" in get_activated_codes()
        total_new_items = []
        for item_type in [2, 3, 4]:
            subsios = [sio for sio in sios if sio.item_type == item_type]
            new_items = []
            candidates = [
                i for i in ItemObject.every
                if i.item_type == item_type and i.price > 0
            ]
            candidates = sorted(candidates,
                                key=lambda c: (c.price, random.random()))
            max_index = len(candidates) - 1
            while len(new_items) < len(subsios):
                if hard_mode:
                    index = random.randint(0, random.randint(0, max_index))
                else:
                    index = random.randint(0, max_index)
                chosen = candidates[index]
                if ("fam" in get_activated_codes() and item_type == 2
                        and chosen.index in HP_HEALING_ITEMS):
                    continue

                restricted_items = None
                if "gun" in get_activated_codes() and item_type == 3:
                    restricted_items = [WeaponObject.get(i) for i in GUNS]
                if "fist" in get_activated_codes() and item_type == 3:
                    restricted_items = [WeaponObject.get(i) for i in FISTS]
                if "ass" in get_activated_codes() and item_type == 3:
                    restricted_items = [WeaponObject.get(i) for i in KNIVES]

                if restricted_items is not None:
                    temp = [i for i in restricted_items if i not in new_items]
                    if temp:
                        restricted_items = temp
                    chosen = random.choice(restricted_items)

                if chosen in new_items and restricted_items is None:
                    continue
                new_items.append(chosen)

            new_items = sorted(new_items, key=lambda ni: ni.index)
            total_new_items.extend(new_items)

        sios = [ShopIndexObject.get(i) for i in xrange(len(total_new_items))]
        for sio, ni in zip(sios, total_new_items):
            sio.item_type = ni.item_type
            sio.item_index = ni.index

        f = open(get_outfile(), "r+b")
        previous = list(sios)
        for address in ["hammer3", "hammer2", "hammer1"]:
            f.seek(getattr(addresses, address))
            num_items = ord(f.read(1))
            f.seek(getattr(addresses, address) + 1)
            chosen_sios = random.sample(previous, num_items)
            chosen_sios = sorted(chosen_sios, key=lambda sio: sio.index)
            for sio in chosen_sios:
                f.write(chr(sio.index))
                sio.shop_rank = int(address[-1])
                sio.inserted_item = False
            previous = chosen_sios
        f.close()
Example #17
0
def do_fiesta():
    print "Please enter a number to choose an option:"
    print "1. Choose my own jobs."
    print "2. Randomize my jobs."

    while True:
        x = int(raw_input("? "))
        if x in [1, 2]:
            break

    print
    if x == 1:
        print "JOB LIST"
        namestrs = [
            "{0:>2}. {1}".format(jco.job_index + 1, jco.name)
            for jco in sorted(JobCrystalObject.every,
                              key=lambda j: j.job_index)
        ]
        maxlen = max(map(len, namestrs)) + 2
        num_per_row = 79 / maxlen
        num_rows = len(namestrs) / float(num_per_row)
        if num_rows != int(num_rows):
            num_rows += 1
        num_rows = int(num_rows)
        ss = ["" for _ in xrange(int(num_rows))]
        while namestrs:
            namestr = namestrs.pop(0)
            s = ss.pop(0)
            s += ("{0:%s}" % maxlen).format(namestr)
            ss.append(s)
        for s in sorted(ss):
            print s
        print
        chosen_jobs = []
        for element in ["Wind", "Water", "Fire", "Earth"]:
            while True:
                x = raw_input("%s job? " % element)
                try:
                    x = int(x) - 1
                    assert x >= 0
                    x = [
                        jco for jco in JobCrystalObject.every
                        if jco.job_index == x
                    ][0]
                    chosen_jobs.append(x)
                    break
                except:
                    pass
        print "Your chosen jobs are: " + ", ".join(jco.name
                                                   for jco in chosen_jobs)
        print
    else:
        JobCrystalObject.class_reseed("fiesta1")
        fight_jobs = [
            jco for jco in JobCrystalObject.every
            if jco.has_fight_command and jco.job_abilities
        ]
        wind_job = random.choice(fight_jobs)
        candidates = [
            jco for jco in JobCrystalObject.every
            if jco.job_abilities and jco is not wind_job
        ]
        chosen_jobs = [wind_job] + random.sample(candidates, 3)

    assert len(set(chosen_jobs)) == 4
    JobCrystalObject.class_reseed("fiesta2")

    crystal_indexes = [jco.crystal_index for jco in chosen_jobs]
    for jco in JobCrystalObject.every:
        if jco.rank <= 2:
            jco.crystal_index = crystal_indexes[0]
        elif jco.rank <= 3:
            jco.crystal_index = crystal_indexes[1]
        elif jco.rank <= 5:
            jco.crystal_index = crystal_indexes[2]
        else:
            jco.crystal_index = crystal_indexes[3]

    NONELEMENTAL_SKILLS = [
        0x8, 0xc, 0xd, 0xe, 0x11, 0x12, 0x13, 0x15, 0x16, 0x17, 0x18, 0x2a,
        0x2b, 0x5f, 0x61, 0x62, 0x90
    ]
    ability_indexes = [
        a.ability for jco in chosen_jobs for a in jco.job_abilities
    ]
    if not set(ability_indexes) & set(NONELEMENTAL_SKILLS):
        print(
            "WARNING! These jobs will not learn a "
            "reliable source of non-elemental damage.")
        print("At least one of them has the Fight skill.")
        x = raw_input("Are you sure you want to continue? (y/n) ")
        if x and x.lower()[0] == 'n':
            remove(get_outfile())
            exit(0)
Example #18
0
            'randomizer version %s.' % VERSION)
     ALL_OBJECTS = [g for g in globals().values()
                    if isinstance(g, type) and issubclass(g, TableObject)
                    and g not in [TableObject]]
     run_interface(ALL_OBJECTS, snes=True)
     if get_global_label() == "FFMQ_NA_1.1":
         DemoPlay = CharacterObject.get(0)
         DemoPlay.name_text = [texttable[c] for c in "Abyssnym"]
         while len(DemoPlay.name_text) < 16:
             DemoPlay.name_text += [0x03]
     hexify = lambda x: "{0:0>2}".format("%x" % x)
     numify = lambda x: "{0: >3}".format(x)
     minmax = lambda x: (min(x), max(x))
     clean_and_write(ALL_OBJECTS)
     if get_global_label() == "FFMQ_NA_1.1":
         write_title_screen(get_outfile(), get_seed(), get_flags())
         enemy_jump = 0xef8e
     elif get_global_label() == "FFMQ_JP":
         enemy_jump = 0xef92
     x = raw_input("Do you want to give Benjamin the power "
                   "to jump over enemies? (y/n) ")
     if x and x[0].lower() == 'y':
         f = open(get_outfile(), "r+b")
         f.seek(enemy_jump)
         f.write(chr(0x80))
         f.close()
     rewrite_snes_meta("FFMQ-R", VERSION, megabits=24, lorom=True)
     finish_interface()
 except Exception, e:
     print "ERROR: %s" % e
     raw_input("Press Enter to close this program.")
Example #19
0
            ['vangram', 'vanillagraham', 'vanilla_graham', 'vanilla graham'],
            'bal': ['balance'],
            'noob': ['noob', 'helper mode', 'helper_mode'],
            'fix': ['stat fixes', 'stat patch', 'statfix'],
            'wiz': ['wizard'],
            'gun': ['guncula'],
            'fist': ['fistula', 'punchdrac'],
            'ass': ['assassin'],
            'int': ['intboost'],
        }
        run_interface(ALL_OBJECTS, snes=False, codes=codes)

        activated_codes = get_activated_codes()
        if "noob" in activated_codes:
            print "NEWBIE MODE ACTIVATED"
            write_patch(get_outfile(), "devanj_noob_patch.txt")
        if "gun" in activated_codes:
            print "GUN SOMA MODE ACTIVATED"
        if "fist" in activated_codes:
            print "FISTICUFFS MODE ACTIVATED"
        if "ass" in activated_codes:
            print "ASSASSIN MODE ACTIVATED"
        if "fix" in activated_codes:
            print "FIXED STATS MODE ACTIVATED"
            write_patch(get_outfile(), "devanj_statfix_patch.txt")
        if "int" in activated_codes:
            print "EQUIPMENT INT BOOST ACTIVATED"
            for wep in WeaponObject.every:
                if wep.index in [0x0A, 0x0B, 0x0D, 0x10]:
                    wep.intl = 2
                if wep.index == 0x25: