Cite as
Cellenseres/Lufia2Decomp
Original
https://github.com/Cellenseres/Lufia2Decomp
Pinned
Cellenseres/Lufia2Decomp @ 6fc15bb88d473c23de106d3d96047186c278af05
Accessed
2026-11-08
Licence
none stated (no LICENSE file; README says it ships no ROM, extracted assets or game data)
Credit
Cellenseres and the project's contributors. The README says the metadata lists 2305 functions, all verified by the maintainers' private differential runs against a supplied ROM.
Notes
Portable C reconstruction of Lufia II's game logic, not a matching disassembly and not a ROM repository. Each routine cites its original ROM address in a comment; the Ancient Cave floor entry and builder are src/cave/ancient_cave.c ($83:9E31 and $83:9013), with cave_grid.c, cave_objects.c, cave_random.c and cave_entry.c (blue-item carry and the $84 enter/exit routines). Battle IP is src/battle/battle_ip.c; capsule monsters are src/party/capsule*.c; field encounter selection is src/battle/field_encounter_selection.c. Line numbers refer to the pinned commit.

Cited on

Claims (25)

Each of the 467 items, from no. 0 (no equipment) to no. 466, has a record reached through a table of 467 offsets at $96:CF69 and a 12-letter name at $9E:C7E8. The record's first nine bytes are copied as a block, and four mask bytes follow; each set mask bit, lowest first, adds a word. Byte 7's lowest set bit picks the equipment slot, byte 8 has one bit per character who can equip the item, the word at +5 is the price the Ancient Cave holds under its floor's limit, the seven words of mask bits 4 to 10 are what equipping adds, and mask bit 15's word names the item's IP attack. Terror Wave names the rest: bytes 0 to 4 use flags, more flags, targeting, icon, and sprite; byte 7's bits, low first, weapon, armor, shield, helmet, ring, and jewel; and the seven added words attack, defense, strength, agility, intelligence, guts, and magic resistance. The table holds 116 weapons, 66 armors, 45 shields, 53 helmets, 41 rings, 33 jewels, and 108 items with no kind bit.src/item/item_records.c L82–173src/item/item_records.c L36–65src/menu/menu_screen.c L1418–1428src/item/item_equipment_kind.c L13–20src/menu/menu_shop_member_equipment.c L18–22src/cave/ancient_cave.c L126–131src/cave/wram.h L42–47src/battle/battle_ip.c L77–90Code
Equipment names its IP attack by number; 158 numbers, from 2 to 168, appear in the item table. Entry n − 1 of a table of pointers at $84:8F10 leads to the attack's record in bank $84, whose byte at +5 is its IP cost and whose name starts at +6. Costs run from 8 to 255; the battle menu offers an attack only when the member's IP byte is at least its cost.src/battle/battle_action_records.c L25–36src/battle/battle_ip.c L77–132Code
Each of the 40 spells has a record reached through a table of 40 offsets at $95:FA5B: an 8-letter name, a byte at +10 with one bit per character who can learn it (in Terror Wave's order), the MP cost at +12, the shop price as a word at +15, and the battle script's offset at +17; Terror Wave calls the byte at +9 the element. Costs run from 0 MP (Reset and Light) to 30 MP and prices to 65000 gold; Guy and Dekar learn none, and Fry and Zap are Artea's alone.src/item/item_records.c L177–223src/item/menu_application.c L9–10src/menu/menu_spell_shop.c L16src/menu/menu_shop_member_spells.c L19Code
All seven characters share one experience curve: reaching level 2 takes 10 experience, level 10 2891, level 50 1548710, and level 99 9999999. The game computes it rather than storing it. Starting from a step of 20 (stored as 5120, in 1/256ths), each level adds the step to a running sum and then grows the step by step × (f + 1) / 256, where f is a factor that changes every eight levels: 190, 64, 49, 31, 17, 13, 5, 2, 2, 1, 1, 1, 1. The requirement is the sum / 256 − 10, except that reaching level 99 takes 9,999,999 flat: at level 98 the routine returns that figure instead.src/party/level_up.c L20–60Code
Each character's stats grow by fixed steps, in sixteenths of a point, from a row of seven bytes that changes every eight levels: 7 characters × $70 bytes at $97:B62C, of which levels 2 to 99 reach the first 13 rows of 8 bytes; the fourteenth row is zeros. A stat at level L is its base plus ⌊(sum of the steps for levels 2 to L) / 16⌋. Terror Wave names the seven bytes HP, MP, strength, agility, intelligence, guts, and magic resistance; the guts byte is 0 in every row, so guts stays at its base.src/party/stats.c L218–243src/party/stats.c L150–215Code
Each character's base stats are seven words at $97:B93C, 14 bytes per character, of which the routine adds only the low byte, each to the growth row's stat in the same place: Maxim starts from 20, 0, 12, 9, 8, 100, 5 (by Terror Wave's names, HP, MP, strength, agility, intelligence, guts, magic resistance).src/party/stats.c L218–243src/party/stats.c L206–215Code
The seven capsule monsters have five forms each, 35 records reached through offsets at $97:DCB8 by the monster's number × 5 + form − 1. The stat routine pairs the byte at +$15 and the five at +$18 to +$1C with six growth codes at +$1D to +$22. Terror Wave names the rest of the record: a 12-letter name, an alignment byte at +14, and the eight stat bytes from +$15 as HP, attack, defense, strength, agility, intelligence, guts, and magic resistance. Foomy's line runs Foomy S, Foomy M, Foomy L, Foomy H, Gold Fox.src/party/capsule.c L247–260src/party/capsule.c L273–330Code
A capsule monster's growth code picks a row of eight rates at $A6:F420, one per 16-level band; each level adds its band's rate, and the sum is divided by 16. The table gives the rates as stored, before the routine halves them: a band equal to the monster's form adds half its rate, and each later band a quarter. The stored rates fall with the bands, from as much as 128 to 0.src/party/capsule.c L43src/party/capsule.c L273–311Code
Each capsule monster's fifth form comes from one fruit and goes back with another: a table of seven item words at $8E:E49A names the fruit that changes it to form 5, one at $8E:E4A8 the fruit that reverts it, and one at $8E:E4B6 the form it must be in and returns to. Foomy turns into the Gold Fox on a Secret fruit at form 4.src/party/capsule_feeding.c L162–202src/party/capsule_feeding.c L10–12Code
The shop table at $97:EE9F holds offsets to 59 shops. Each starts with a kind byte, a flag byte, and a third byte; flag bit 0 lists the party's own items, each of bits 1 to 5 adds a list, and bit 7 one more menu entry. The first four lists are words ended by 0, and the fifth is bytes ended by $FF. Terror Wave names bit 0 pawn, bits 1 to 5 prize coins, items, weapons, armor, and spells, and bit 7 sell.src/menu/menu_screen.c L1034–1099src/menu/menu_screen.c L941–958Code
The Ancient Cave's enemies by floor: an enemy on floor N is one of the six entries from 2(N − 1) of a 200-byte table of monster numbers at $94:D95C, which names 149 different monsters in all. Floor 1 holds Goblin, Goblin Mage, Armor goblin, Regal Goblin, Troll, Ork; floor 98 Dark Warrior, Ochi Warrior, Sly Fox, Pierre.src/cave/cave_objects.c L106–117Code
Each enemy shown on a field map stands for an enemy group the map lists: when the map places an encounter actor, the game takes the actor's slot, reads the group in that slot of the map's encounter list, and sets up that slot's enemies from it. In the Ancient Cave the list is read from memory, where the cave writes it, rather than from the ROM.src/battle/field_encounter_selection.c L7–44Code
How battles start on Lufia II's world map, and at what rate, isn't read yet.src/world/world_scene.c L1592–1617Unsourced
Once an action isn't rejected by the target's status or interrupted, its damage is a base value scaled, given a random bonus, cut by half the target's defense, halved, and trimmed by a factor: X = base × scale / 16; X + X × v / 256, with v random from 0 to the action's variance − 1; less half the target's defense, at least 0; halved; then less X × F / 256, where F is the action's damage-factor byte. First a roll from 0 to 99 is made against the action's chance byte: below it, the action's own scale stands and the target's defense counts as 0, a heavier hit that ignores defense; otherwise the scale is 16, times 1. Healing takes the scale and the random bonus only. A scaled base past 65,535 runs into a $00 byte in the code rather than a result. The base, chance, scale, variance, defense, and factor come from the action's battle script, which isn't read here, and the lines read hold no miss test.src/battle/battle_target_action.c L717–798src/battle/battle_target_action.c L129–217Code
Each defeated enemy can drop its item: the game needs a roll from 0 to 99 below the drop's chance, which is half the high byte of the stored drop word, and then a 1 on a roll from 0 to 3, so a chance of 40 drops on about 10% of kills. It rolls for each drop entry in the enemy's list, a later success replacing an earlier one, and stops rolling once the battle has won an item, so a battle pays at most one dropped item.src/battle/battle_target_action.c L677–706Code
Running from a battle has no roll in the code read: unless the battle's special-encounter flag is set, the party gets away at once. A battle loaded from the game's list of special encounters sets the flag, and there the attempt fails with a message and the battle goes on. When an enemy or the capsule monster runs, it alone leaves: it takes the status a defeated fighter gets, and the battle goes on. The routine's caller and the routines it calls aren't read, so a roll made there isn't ruled out.src/battle/battle_target_action.c L30src/battle/battle_target_action.c L663–667src/battle/battle_encounter_loader.c L238–248src/battle/battle_encounter_loader.c L223–224Code
Taking a hit from an enemy fills a party member's IP gauge, more for a hit that takes a larger share of the HP the member had. The gain is m × g / 256 + 12, at most 255, where m = (256 − cos a) × 2, with a the hit's share of the member's HP in 256ths divided by 4 and rounded (64 is a right angle, so m runs from near 0 to 512), and g is the low byte of a word in the member's battle record times 128 / 100, at most 255 (199 instead when the word is $C800 or more). The gauge stops at 255. In the HP-change routine read, only an enemy's hit that leaves the member standing adds IP; a member who is knocked out drops to 0.src/battle/battle_target_action.c L37src/battle/battle_target_action.c L543–576src/battle/battle_target_action.c L663–711Code
The Ancient Cave has 99 floors, and the game builds each of the first 98 at random as the party reaches it; the 99th is a fixed map. Entering clears the floor count and arriving on the cave's map with a count of 0 sets it to 1; each floor is built with the count as its number and the count rises by one after it, and when the count stands at 99 the game loads the fixed map instead of building one.src/text/scene_label_callers.c L64–66Code
Each Ancient Cave floor is built rather than picked from stock maps. The builder lays out up to seven rectangular rooms, each one to four cells wide and one to four tall (the size the average of two draws), working left to right in bands down a grid 16 cells wide, and keeps a room only if it ends before column 9 and row 15 as the code counts; a room of a single cell is widened by one. Later passes, which the decompilation names for linking the floor, removing duplicate links, placing the start, the treasure room, the objects and chests, and drawing the cells, finish the floor.src/cave/wram.h L37–38src/cave/wram.h L131src/cave/ancient_cave.c L1322–1346Code
Which enemies an Ancient Cave floor can hold depends only on its number: each enemy placed on floor N is entry 2(N − 1) plus a random 0 to 5 of a 200-entry table, so each floor has six kinds, a floor shares four of them with the next, and each entry serves three floors. A floor makes 4 to 7 tries to place an enemy, each at a random spot of a random cell, and a try fails when no cell is found or the spot is beside the start or another object; a treasure room adds up to 13 more, and a floor holds at most 20.src/cave/cave_objects.c L95–136src/cave/ancient_cave.c L717–755src/cave/ancient_cave.c L652–697Code
An Ancient Cave floor has at most eight chests. The builder scans the grid for 2-by-2 blocks of cells in one room and tries a chest in each block, marking it used, until eight are placed or the grid scan ends; one floor in 16 can also get a treasure room, a 2-by-2 block that takes up to eight chest tries of its own and a cluster of up to 13 enemies.src/cave/ancient_cave.c L756–790src/cave/ancient_cave.c L698–713src/cave/wram.h L143–157Code
From floor 21 on, an Ancient Cave floor's first chest can hold Providence (item $2D): the chance is about the floor number in 60, so certain from floor 60, unless an Iris treasure took the chest. Once a chest holding Providence has been opened, no more are placed in that visit.src/field/field_object_rewards.c L135–150Code
Entering the Ancient Cave takes everything from the party except its blue-chest items. The game moves each item on the blue list from the bag and from the four party members' equipment to a list of its own, saves a copy of the party, then clears all but the first 14 bytes of each of the seven members' records, the bag, the gold and the play time, puts 10 Potions in the bag, gives back the blue items, and rebuilds the seven members from their default records; when the byte at $0A7F, which neither source names, is 7, it also returns every capsule monster to level 1, a step no probe has covered.src/system/default_records.c L162–176src/party/capsule.c L481–488src/cave/cave_entry.c L21–41Code
A party wipe in the Ancient Cave, a battle there or on its bottom floor that ends with every party member down, ends the visit with nothing gained. The game marks the visit lost, clears the party again without giving back its blue items, and counts the defeat; when the party then leaves, the exit skips the collecting, restores the copy saved at the entrance, and returns only the blue items the party brought in, so that visit's blue-chest finds and Iris treasures are lost.src/cave/cave_reset.c L136–170src/battle/battle_outcome.c L30–76Code
Between visits the game keeps, outside the copy the exit restores, a count of entries and one of wipes, the total time spent in the cave, and the deepest floor reached; what else carries over is the Iris flags and the blue items as the party holds them.src/system/wram.h L266–272Code