Lufia II: Rise of the Sinistrals (Estpolis Denki II in the Japanese original, Lufia in the European and Australian editions) is a Game by Taito/Natsume released for the SFC/SNES 1995–1997. It's an awesome RPG that features a nice story and turn-based combat with stats and RNG and items and spells and all the good things. A distinct feature of it is the IP system which allows special moves bound to equipment and paid for with damage taken.
The Random Number Generator
There is something interesting about the way how random numbers are drawn in this game. Well, two things actually:
- When the console powers on (and the publisher logos have shown), its seed is always initialized to the exact same values.
- Its state is only changed whenever a value is pulled from the random pool.
This means it is possible, on a new game, to accurately predict each and every movement, attack, damage, and loot drop that "luck" will grant you.
The RNG lives in the S-CPU memory at adresses 7E0521 to 7E0557 as well as 7E0559 (source: Dragondarch quoting Gunty on the Speed Demos Archive forum). The former is the current random state and the latter is a counter that acts as a pointer into the range and determines which value will be pulled out next. When the end is reached, the next range of values will be generated following this simple rule:
i = i XOR (i + 31)
Note that in order to get a consistent new game, it must be factory reset, so there are no saves on the cartridge and RETRY and GIFT modes must not be unlocked. You can easily accomplish that by holding both Start and Select right before the intro plays and confirm the erase of all data. Also, the console has to be hard reset in order for the RNG memory to be reinitialized (before erasing all saves, not after), which you can do by simply flipping the power switch off and back on again.
This is where it gets interesting.
Because of this well behaved randomness at all times in the game, you can manipulate your chances up to an almost arbitrary point into the game. People usually stop at either Catfish, Camu or Tarantula, because for reasons I'll explain later, it is not easy to pull off, but e.g. Zheal in his any% NMG 3:23:47 run took it all the way right to Gratze.
Now, why is this trick not the easiest to perform? Everything's predetermined and turn based, so if you take your time, it should be super easy, right?
Well, that's almost correct, were it not for a minor detail: The movement of villagers is also random, and they request numbers every frame, which for the SNES is around 60 times per second. So in towns, your input has to be frame perfect in order to keep the RNG in a known state.
This also means that different localizations will have different random states after dialogues because the number of characters in a given bubble will almost certainly be different. That and the fact that different versions have different puzzles in some places makes manipulations highly version dependent. I will be focusing on the unpatched North American release (U 02 NTSC 60 rev 1.0, Header Checksum: BA68, CRC32: 20F2AC29). It may also apply to the graphical patch that fixes the Dual Blade scene, since that should in theory not change any of the RNG values, but I have not tested that yet.
It's not as bad as it seems, though, because all you do in towns is usually walking along a precise route, which due to the walking mechanics always takes the exact same amount of frames, or talk to shop owners or during a cutscene, which often is easy to get perfect, since you can hold down the A or L button before a dialog box finishes to have it dismissed perfectly.
Having said that, there are still a few things to keep in mind. The dialogs tick their text at one character per frame, and while most dialogs do not have people walking around draining the RNG, or if they do, the have bubbles long enough to easily get them perfectly dismissed, there are some places where you have notoriously short boxes in a town with people running around like madmen. The most prominent of those must be the one between Maxim and Guy just before the introduction of Idura in Tanbel, which has a live six letter box (just short of 100ms). But there are also less obvious places where things can go wrong, such as the Shop in Sundletan, which features an armored guard that can walk around the shop and thus is querying the RNG while you sprint towards the store clerk trying to hit A in time (to be fair, it's not that hard, because interaction can be buffered just like walking).
I also found this any% glitchless 4:10:05 run by FeralPigMan rather instructive, since it includes a Tarantula manip and he goes a little slower and talks a bit about what he's doing.
How the RNG is affected:
There are basically five types of scenes you can be in that have different kinds of impact on how numbers are pulled from the RNG and thus cause its state to change:
- the overworld map,
- and battle screens.
I've already mentioned towns before, and they are indeed the most critical to pay attention to, since simply standing around in one causes a whole bunch of changes to the random state in mere split seconds. This is where you have to pay most attention to getting your input right, because you cannot pause at all during navigation and sometimes even dialogs.
Menus, such as the character menu (X) or the ring menus (Select) are a little easier to handle since you can take your time, and only selections have a potential impact on the RNG. Navigating a menu by itself does not call the RNG at all. Only actions like using a potion, casting a spell or feeding a capsule monster do.
The overworld map is kind of a special case, since it gives you very good control over how the random counter increments. The first four steps on the map do not change RNG whatsoever. That means you can take four steps, open the character menu, take another four, menu again, etc. ad infinitum and never change the RNG at all. Any step further increments the pointer by exactly one. So by utilizing this behaviour, you can potentially fix an error in manipulation, if you end up with the counter being a small amount ahead.
Dungeons, being one of the prominent features of the game, have themselves a bunch of different types of RNG polling available, the most obvious being enemy movement. Since enemies only every move when the player does, you have absoloute control over what they do and are not time constrained. Basically, there are, in terms of RNG, three kinds of enemy movement:
- Player independent random walk
- Player dependent with random bias
- Deterministic pattern based, either with or without player dependence
The first category is the simplest: Whenever a step is takes, the enemy decides where to move based on a random roll. Of course, it is not allowed to collide with walls or other entities (TODO: find out if a collision causes a reroll). This is your typical Jelly or Lizard behaviour.
The second category is tricky, since it uses the RNG, but is also affected by the player's position. Usually, when walking through a dungeon, you can go by Manhattan distance rules, i.e. going north and then east is the same as going east and then north. This only holds true, if the route you're taking does not influence player-dependent enemy movement in different ways. Bats and Ninjas are examples of this category.
The third category can almost be ignored. It includes enemies that follow a strict path (such as the Goblins, which always walk straight until they hit a wall and then take a right turn) or base their movement solely on the player's (such as the Mushrooms, which always move in a 90° shift from the player). They can, of course, still affect other enemies by blocking their random walk, but do not query the RNG themselves.
Another thing that really messes up the RNG is cutting bushes. In fact, anything that uses the particle system will (the leaves from bushes, the glitter from obtaining quest items, etc.).
Placing down pots (or other holdable items) is a rather curious entry, since its effect on the RNG depends on whether the D-Pad is pressed during placement. Pay close attention to that when speedrunning, since it is rather easy to accidentally place the pot too soon (or too late, if your route needs you to place it with the D-Pad down).
Pushing pillars or blocks, apart from the enemy actions that the player movement itself might cause, will not change random state. Neither does opening the ring menu nor turning around with R.
Battle screens operate very similarly to menus (well, they basically are menus). In addition to the actions you take, entering as well as leaving the battle screen causes the RNG to iterate (to determine which enemies you encounter and what your drops or flee chances are). The nice thing about battles is that you can undo most mistakes by just going back, except for the last command which executes the turn. Note that enemies decide which character slot they attack, regardless of which character is in that position, and swapping characters does not affect RNG, so you can target enemies' attacks to specific party members by simply putting them into the attacked position.
I am currently writing a detailed description of the route I will be taking (I' still in the process of learning it) as well as a quick reference of the major actions taken for use during runs. Since I am pretty much a noob to speed running in general as well as Lufia II in particular (my success rate of the Catfish manip is at about 40% with a PB of 10:25), this will obviously take some time to complete, but I will regularly update both.