Everyone I've asked who's looked at the USUM source code has had no idea how to determine the order of chained modifiers. It uses a stack, but it's not clear at all which order different modifiers are placed on the stack. I also wouldn't even between to know where to look to try to figure it out in real-time with RAM dumps or something. As a result, I went the good ol' route of attempting to bruteforce situations where I could prove an attack misses when it could potentially always hit. Since we understand everything besides modifier chaining order, we have a lot of the ground work laid out. We have a few additional things to consider:
- There are a finite amount of base accuracy values to work with. 50, 55, 60, 70, 75, 80, 85, 90, 95, and 100 are the only possible base accuracy values, and a few are incompatible with Hustle (50, 55, and 60).
- Hypnosis is the only 60% accurate move, Sing / Supersonic / Grass Whistle are the only 55% accurate moves, and Dark Void / Hurricane or Thunder in sun / Wonder Skinned status moves are the only way to get 50% accurate moves.
- It would be pointless to check something like 85% vs. 86% for an accuracy value, as the amount of tests to prove something is 85% rather than 86% or similar is insanely high. Rather, we want to have something like a 99% vs. 100% test, where it is possible to miss. That way, all you have to do is try over and over again, and eventually you'll miss, which is enough to prove it's not 100%. So something like 98 vs. 100 or 99 vs. 100 will work.
- Accounting for Micle Berry and no stat boosts/drops, modifiers reaching 82 vs. 83 would also work (Micle would scale that to 98 or 100).
- Accounting for stat boosts / drops, the following pairs would also work work. Note that you can still use Micle + Zoom Lens or what have you by Flinging the Micle Berry.
Boosts / drops (no Micle)
Boosts / drops (no Micle)
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
Boosts / drops (with Micle)
Boosts / drops (with Micle)
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
In theory, what you would want to do first is generate all possible combinations of modifier chaining order. For example, suppose you have Tangled Feet, Victory Star (user), and Bright Powder. These would be the possible orders that they
could be chained:
[2048, 4506, 3686]
[2048, 3686, 4506]
[4506, 2048, 3686]
[4506, 3686, 2048]
[3686, 4506, 2048]
[3686, 2048, 4506]
However, we can eliminate several of these, as in modifier chaining, swapping the first 2 slots will always be mathematically equivalent. So you can cut it down a bit:
[2048, 4506, 3686]
[2048, 3686, 4506]
[4506, 3686, 2048]
Next, you chain each one of these together. In our example:
[2048, 4506, 3686] = 2027
[2048, 3686, 4506] = 2027
[4506, 3686, 2048] = 2028
We've passed our first check - if the chained modifiers were all the same no matter which order you applied them in, you could move on to the next set of combinations.
Next, you need to apply 2027 and 2028 to every possible
base accuracy. If applying 2027 vs. 2028 is inconsequential to base accuracy values that exist, we again need to move on to the next set of combinations.
Finally, we need to check to see if any of those resulting values are testable - i.e. if, after applying the modifier, we can further manipulate the accuracy / evasion calculation to be 98 vs. 100 or something similar. In our example, one of these does exist with a 100 base accuracy.
pokeRound(100*2027/4096) = pokeRound(49.4873046875) = 49
pokeRound(100*2028/4096) = pokeRound(49.51171875) = 50
In this case, we can use +3 accuracy to get a further 2x multiplier and have a 98 vs. 100 test case. In this case, it does miss, which means those 3 must be chained in one of these possible orders:
Victory Star (user) -> Tangled Feet -> Bright Powder
Tangled Feet -> Victory Star (user) -> Bright Powder
Tangled Feet -> Bright Powder -> Victory Star (user)
Bright Powder -> Tangled Feet -> Victory Star (user)
In theory, all you have to do then is generate those combinations and run the comparisons in a giant loop.
**********************
But of course, that's all in theory. I gave a good college try at implementing this logic myself; the hardest part by far is generating all of the combinations. The issue is that when I did, besides the Bright Powder and Zoom Lens vs. Tangled Feet / Victory Star tests, I wasn't able to bruteforce
any combinations that allow me to prove positively the order of any other modifiers. The combinations simply don't exist, if I wrote my code correctly. That's not to say there's not plenty of combinations where the difference matters, but they aren't for cases that I can test empirically (e.g. 54% vs. 55%). It also doesn't do me any good to check 98 vs. 100 if the roll is expected to land on the side of 100. The sheer amount of tests needed to prove something is 100% accurate rather than 98% is astronomical. To give an example, I spent 2 hours on one 98 vs. 100 test (60 base accuracy with Gravity, Bright Powder, Victory Star, Zoom Lens, and Tangled Feet) and only completed 255 trials. It never missed, so it's
probably 100, but you can't know for sure.
You could improve the time it would take to do empirical testing by loading a Battle Video in Citra and editing the 4-byte RNG seed of that Battle Video at 0x01E8. Then, you just play the Battle Video back with the new RNG seed. But even
if you did that, you still would only prove that a specific range of combinations are possible to produce the chained modifier. To give an example, here's another one with 75 base accuracy and Victory Star, Zoom Lens, Hustle, Bright Powder, Gravity, and Tangled Feet:
https://pastebin.com/MbqSeJT5
Say you were able to prove that 59 was correct, rather than 60. There's still
26 possible combinations that could be happening that would produce 59 when chained. Now, it's not trivial to do so; after all, you eliminate 694 impossible combinations. The trouble is that I suspect the value really is 60 here. If that's right, then you really only eliminate 24 combinations, which is nice but fairly trivial.
It's quite possible that I didn't write my program well enough to bruteforce combinations though; maybe I was just a bad coder and didn't do things right. In any case though, I don't think there's anything more I can do. I'd say the best options at this point are:
- Figure out how modifier chaining works by understanding the USUM source code better
- RAM edit accuracy success to force a miss / hit (Anubis has done this before so I know it's possible)