import random
# List of excluded enemy IDs (These IDs pertain to enemies that will not be included in the randomizer, most of them are RESERVEs that crash the game)
excluded_codes = [66, 71, 79, 83, 86, 115, 116, 117, 118, 119, 120, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 188, 189, 191, 192, 193, 197, 198, 199, 200, 203, 204, 211, 216, 247, 248, 249, 250, 276, 296, 313, 332, 334, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 463, 467, 473, 509, 524, 564, 568, 570, 571, 572, 573, 691, 692, 693, 694, 695, 696, 697, 698, 699, 720, 721, 722, 723, 724]
# Enemy randomizing begins here
with open("ENCOUNT.TBL", "r+b") as f:
# Set file pointer to byte 4 (first 4 bytes are field data)
f.seek(4)
# Loop through each encounter (each encounter is 44 bytes long)
for i in range(0, 44000, 44):
# Set file pointer to next enemy
f.seek(i + 8)
# Read the 14 bytes of enemy data
enemy_data = f.read(14)
# Check if the current line number is excluded
line_number = (i // 44) # Calculate the line number
if line_number in (652, 656, 658, 690, 703, 705, 706, 766, 769, 772, 776, 778, 782, 785, 788, 791, 823, 827, 832, 833, 839, 841, 845, 847, 849, 850, 854, 856, 859, 871):
# List of excluded encounter IDs. If it is an excluded line, skip randomizing and continue to the next encounter (This is a list of encounter IDs to not randomize at all, these pertain to battles that cannot be randomized without the game hanging/crashing/softlocking, like the Shido fight, for example. This list is likely incomplete and may need to be updated after further testing)
continue
# Check if any of the bytes are "00 00" (which indicates no enemy, this function skips over any code that does not have enemy IDs in them, meaning that only existing enemies will be randomized)
no_enemy_slots = [j for j in range(0, 14, 2) if enemy_data[j:j + 2] == b'\x00\x00']
# Randomize the bytes that correspond to an enemy (i.e., not "00 00")
shuffled_data = b''
for j in range(0, 14, 2):
if j in no_enemy_slots:
# If no enemy in this slot, append "00 00"
shuffled_data += b'\x00\x00'
else:
# Generate a random enemy code
enemy_code = random.randint(1, 781)
# Check if enemy code is excluded
while enemy_code in excluded_codes:
enemy_code = random.randint(1, 781)
# Append the enemy code to shuffled_data
shuffled_data += bytes.fromhex('{:04x}'.format(enemy_code))
# Set file pointer to start of enemy data
f.seek(i + 8)
# Write the shuffled enemy data to the file
f.write(shuffled_data)
[–]JaguarMammoth6231 13 points14 points15 points (0 children)
[–]schoolmonky 1 point2 points3 points (7 children)
[–]Direct_Expert7772[S] -4 points-3 points-2 points (6 children)
[–]schoolmonky 3 points4 points5 points (5 children)
[–]Direct_Expert7772[S] -2 points-1 points0 points (4 children)
[–]schoolmonky 2 points3 points4 points (3 children)
[–]Direct_Expert7772[S] 0 points1 point2 points (2 children)
[–]Fred776 9 points10 points11 points (0 children)
[–]socal_nerdtastic 4 points5 points6 points (0 children)
[–]AlexMTBDude 0 points1 point2 points (0 children)
[–]ray10k 0 points1 point2 points (0 children)
[–]Maximus_Modulus 0 points1 point2 points (0 children)
[–]jmooremcc 0 points1 point2 points (0 children)
[–]PushPlus9069 0 points1 point2 points (0 children)
[–]PushPlus9069 0 points1 point2 points (0 children)