Perfect Item Code [Vega]
#6
After some tests I would like to present my results here:

In fact, it is NOT because of Wiimmfi that these codes do not work perfectly. Even on NewWFC and offline, woodboxes and leafpiles give out random items. But this is due to the fact that the DecideItem function is also called when you hit those. The game passes the ItemBox setting of the leafpiles or the box as a function argument and thus calculates which item will be given. That's why the code does not work properly on tracks like Toad's factory or Maple Treeway, let me explain: You drive through an item box and the code backs up the probability table of the regular items. Then the code sets the probability of a green shell high. If you drive through a leafpile afterwards, the entire (!) probability table of the regular items is stored to the probability table of the special items and overwrites all previous values, which results in them throwing out shells as well. The other way around, if you first drive into the leafpiles and then into an item box, the entire probability table of the special items is stored to the probability table of the regular items. This will make that you can only get certain items on certain positions, e.g. star on the fourth place or a mushroom on the second place. All in all, it is rather dangerous to backup the probability tables and then change them. But more than that, it is actually not necessary either!

After investigating the DecideItem function, I now understand it as well (at least for the most part):
The game checks all items (starting with the Green Shell) in the game and certain conditions for certain items (No Mega in Mega etc...). If an item is allowed, the probability of this item is added with all probabilities of the previous items. This means that we get a summed chain of probabilities for our current position, each of them stored as halfword at a certain address in memory. If an item is not allowed, the same value is simply stored one right after the other, which results in the difference of these two values then being 0 (0% probability to get this item). After all items have been checked, a random number is calculated and it is determined in which interval of the summed probabilities this random number lies. This interval number (= Item) is then the result of the DecideItem function and holds your Item.

Every time we touch an item box or a leafpile will give an item, the summed up probabilities are updated at the address mentioned earlier. Although the values change, this address is static, that is, it is always at the same position (even on every new boot). Here are the addresses for each region:

Adress of Positional summed up Item probabilities
NTSC-U: 809BEE6C
PAL:       809C3674
NTSC-J: 809C26D4
NTSC-K: 809B1CE4

Just use the memory viewer on Dolphin or Vegas Memory Editor on the console and navigate to this address. You will see how the summed up probabilities change every time you drive through an item box or a leafpile if an item is given.

Cutting a long story short, the point here is that the values in the probability table are only indirectly used to calculate the item. The probabilities are loaded from these tables and the summed probabilities of all items of your current position are stored at the above address. Afterwards, these values are used to determine what item you will get. Therefore, it is only sufficient to overwrite the values loaded from the original probability table before summing them with the previous probabilities and then storing them. And I have found this address and can thus create a code that:

1. is much shorter than the current version, but works just as efficiently,
2. works without backing up the original table,
3. has no problems for courses with special item probabilities and
4. The deactivator is simply the default instruction.

And that's actually still not all: With a few more instructions it's even possible to combine the codes "Perfect Item code", "Selective Item Max Probability" and "positional Selective Item Max Probability" in one code with only replacing branches to modify the behavior of the code.

I will post the code as soon as I have time to do it. And sorry for the long explaining text, I tried to make it as short as possible Tongue
Reply


Messages In This Thread
Perfect Item Code [Vega] - by Vega - 10-27-2018, 10:43 PM
RE: Perfect Item Code [Vega] - by CLF78 - 06-12-2020, 12:48 PM
RE: Perfect Item Code [Vega] - by 1superchip - 06-17-2020, 01:10 PM
RE: Perfect Item Code [Vega] - by coolio - 06-17-2020, 01:45 PM
RE: Perfect Item Code [Vega] - by Unnamed - 07-21-2023, 12:09 PM
RE: Perfect Item Code [Vega] - by Vega - 07-21-2023, 05:25 PM
RE: Perfect Item Code [Vega] - by Unnamed - 07-21-2023, 08:33 PM
RE: Perfect Item Code [Vega] - by Vega - 07-21-2023, 09:21 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)