Perfect Item Code [Vega]
#1
Perfect Item Code [Vega]

This code will increase the odds of you getting your desired item to 100% as long as you can get that item 100% legitimately (position, room size, what others are holding, etc etc).

How the code works~
When you hit a box, your latest updated item probability table is backed up (copied over to an unused spot in memory)
The code checks if the item you want can be had in your position (compares probability of said item on current 'position row' to value of zero)
If not zero, code executes, your odds of getting said item to increase to max value that game allows
If zero, code simply doesn't execute

NTSC-U
C27ACB64 00000005
3868FFFE 3C808165
396000E4 A5830002
B5840002 356BFFFF
4082FFF4 7FE3FB78
60000000 00000000
C27ACBC4 00000008
80850004 3D808164
818C0000 2C0C0000
40A2002C 3984FFFE
396000E4 7D6903A6
3D608165 A6EC0002
B6EB0002 4200FFF8
3D808164 39600001
916C0000 00000000
2834XXXX YYYYZZZZ
C27ACBC8 00000007
3D808165 618C0002
7D8C1A14 396000WW
7D8B6214 A18C0000
2C0C0000 41820014
7EE41A14 7D8BBA14
39607FFF B16C0000
2C000000 00000000
E0000000 00000000
2834XXXX YYYYZZZZ
C27ACBC8 00000005
3964FFFE 3D808165
3AE000E4 7EE903A6
A6EC0002 B6EB0002
4200FFF8 2C000000
60000000 00000000
E0000000 80008000

PAL
C27BB5C4 00000005
3868FFFE 3C808165
396000E4 A5830002
B5840002 356BFFFF
4082FFF4 7FE3FB78
60000000 00000000
C27BB624 00000008
80850004 3D808164
818C0000 2C0C0000
40A2002C 3984FFFE
396000E4 7D6903A6
3D608165 A6EC0002
B6EB0002 4200FFF8
3D808164 39600001
916C0000 00000000
2834XXXX YYYYZZZZ
C27BB628 00000007
3D808165 618C0002
7D8C1A14 396000WW
7D8B6214 A18C0000
2C0C0000 41820014
7EE41A14 7D8BBA14
39607FFF B16C0000
2C000000 00000000
E0000000 00000000
2834XXXX YYYYZZZZ
C27BB628 00000005
3964FFFE 3D808165
3AE000E4 7EE903A6
A6EC0002 B6EB0002
4200FFF8 2C000000
60000000 00000000
E0000000 80008000

NTSC-J
C27BAC30 00000005
3868FFFE 3C808165
396000E4 A5830002
B5840002 356BFFFF
4082FFF4 7FE3FB78
60000000 00000000
C27BAC90 00000008
80850004 3D808164
818C0000 2C0C0000
40A2002C 3984FFFE
396000E4 7D6903A6
3D608165 A6EC0002
B6EB0002 4200FFF8
3D808164 39600001
916C0000 00000000
2834XXXX YYYYZZZZ
C27BAC94 00000007
3D808165 618C0002
7D8C1A14 396000WW
7D8B6214 A18C0000
2C0C0000 41820014
7EE41A14 7D8BBA14
39607FFF B16C0000
2C000000 00000000
E0000000 00000000
2834XXXX YYYYZZZZ
C27BAC94 00000005
3964FFFE 3D808165
3AE000E4 7EE903A6
A6EC0002 B6EB0002
4200FFF8 2C000000
60000000 00000000
E0000000 80008000

NTSC-K
C27A9984 00000005
3868FFFE 3C808165
396000E4 A5830002
B5840002 356BFFFF
4082FFF4 7FE3FB78
60000000 00000000
C27A99E4 00000008
80850004 3D808164
818C0000 2C0C0000
40A2002C 3984FFFE
396000E4 7D6903A6
3D608165 A6EC0002
B6EB0002 4200FFF8
3D808164 39600001
916C0000 00000000
2833XXXX YYYYZZZZ
C27A99E8 00000007
3D808165 618C0002
7D8C1A14 396000WW
7D8B6214 A18C0000
2C0C0000 41820014
7EE41A14 7D8BBA14
39607FFF B16C0000
2C000000 00000000
E0000000 00000000
2833XXXX YYYYZZZZ
C27A99E8 00000005
3964FFFE 3D808165
3AE000E4 7EE903A6
A6EC0002 B6EB0002
4200FFF8 2C000000
60000000 00000000
E0000000 80008000

WW Item Values:
Green = 00
Red = 02
Banana = 04
Fib = 06
Shroom = 08
Triple Shroom = 0A
Bomb = 0C
Blue = 0E
Shock = 10
Star = 12
Golden = 14
Mega = 16
Blooper = 18
Pow = 1A
TC = 1C
Bullet Bill = 1E
Triple Green = 20
Triple Red = 22
Triple Banana = 24



List of ASM Sources:
Source (1st ASM; re-backup Game's Item Table if In-Race Room Size decreases during Race):
##################
##START ASSEMBLY##
##################

#

###############################
##Loop Loading Address Config##
###############################

addi r3, r8, -0x0002 #Do a minus -0x2 on the mem location of r8 and store it in r3. this mem location is exactly -0x2 away from the very first halfword for the item probability table which is the halfword for 1st place Green Shell probability

####################################
##Item Table Mem 81 Address Config##
####################################

lis r4, 0x8165 #Set 1st half address for where the overwritten table will be stored if room size ever decreases during race

#########################################
##Subic. Loop Countdown Register Config##
#########################################

li r11, 0xE4 #Load E4 in r11, there are a total of E4 halfwords for the entire item probability table

###################
##De_crement Loop##
###################

de_crement:
lhzu r12, 0x0002 (r3) #First, load the first halfword of the item table, increase mem location by 0x2 every time this ASM is done to load the next halfword of the table
sthu r12, 0x0002 (r4) #First, store the current halfword item probability value to mem location 0x81650002. The address will increase by 0x2 every time this ASM is done so each halfword it in its own space.
subic. r11, r11, 1 #Subtract one from r11 every time this ASM is done. Thus this will cause exactly E4 amount of halfwords to be loaded and stored
bne+ de_crement #If r11 does NOT equal 0, jump backwards to lhzu and repeat. If r11 does equal 0, continue down to next ASM

###############
##Default ASM##
###############

mr r3, r31 #Default ASM

#####################################################
##Notes About Using Registers 3 & 4 w/o Restoration##
#####################################################

##In the default ASM, r3 gets written to after this entire code is executed, so it is safe for use##
##The next function at the following address, r4 gets written with the variables of r31 and integer 24##

#

##################
###END ASSEMBLY###
##################



Source (2nd ASM; backup Game's entire Item Table. Please note that if in-race room size decreases before you grab first box, that it is not an issue. As this ASM will be executed after the 1st ASM):
##################
##START ASSEMBLY##
##################

#

###############
##Default ASM##
###############

lwz r4, 0x0004 (r5) #Default ASM


######################
##Load Status Number##
######################

lis r12, 0x8164 #Set up first half address for where the status check number will be read/stored
lwz r12, 0 (r12) #Load the status check number from mem location 0x81640000. If the ASM is being executed for the very first time of race, this number will always be 0, thus the first/original version of the item table for that race room size for the exact time when you pick up your first box

##############################
##Status Number Verification##
##############################

cmpwi r12, 0x0 #Compare status check number value to 0
bne+ dont_backuptable #If NOT equal to 0, skip entire code, don't backup first/original item table

############################
##Loop Load Address Config##
############################

addi r12, r4, -0x0002 #Add -0x2 to mem location of r4, store result into r15. The mem location on r15 will be exactly -0x2 away from the very first halfword for the item table which is the halfword for 1st place Green Shell probability

##############
##CTR Config##
##############

li r11, 0xE4 #Load E4 in r11, there are a total of E4 halfwords for the entire item probability table
mtctr r11 #Copy the value of r11 to the CTR

####################################
##Item Table Mem 81 Address Config##
####################################

lis r11, 0x8165 #Set 1st half address for where the first/original table will be stored (this will be whatever the table is configured as when you pick up your first box)

###################
##De_crement Loop##
###################

de_crement:
lhzu r23, 0x0002 (r12) #First, load the first halfword of the game's item table, increase mem location by 0x2 every time this ASM is done to load the next halfword of the table
sthu r23, 0x0002 (r11) #First, store the current halfword item probability value to mem location 0x81650002. The address will increase by 0x2 every time this ASM is done so each halfword it in its own space.
bdnz+ de_crement #If CTR is not 0, branch back to the start of the loop and repeat

#############################
##Status Number Application##
#############################

lis r12, 0x8164 #Set up first half address for where the status check number will be read/stored
li r11, 0x1 #Now that first/original table is stored. We don't want this code to execute again for the rest of the race. Load 1 into r11 for new status check number
stw r11, 0 (r12) #Store status check number of 1 (don't execute again for rest of race) to mem location 0x81640000. Pls note that Mem 81 is reset by the game every race (cleared), no need for a deactivator for this ASM

dont_backuptable:

########################################
##Note about using r23 w/o restoration##
########################################

##r23 gets written to at a later address with the function add r23, r4, r3##
##Therefore, it is safe to use freely##

#

##################
###END ASSEMBLY###
##################



Source (3rd ASM; Check to see if the Item can be legitimately received for the current in-race room size position. If not, don't execute code. If so, max out Desired Item's Probability; code activated.):
####################
###START ASSEMBLY###
####################

#

####################################
##Setup Item Table Mem 81 Location##
####################################

lis r12, 0x8165
ori r12, 12, 0x0002

########################################################
##Locate Your 'Positional Row' On Backed up Item Table##
########################################################

add r12, r12, r3 #Add r3 and r12 together. Result (stored back into r12) will hold the address to the green shell halfword for whatever position you are in.

########################
##Load Your Item Value##
########################

li r11, 0xWW #Load User's Item Value (WW)

#################################################################
##Locate Your Exact Item Prob. Halfword Spot on Backed up Table##
#################################################################

add r12, r11, r12 #Add r11 and r12 together. You will now be located at your item's halfword location for your position on the item table

#################################
##Item Probability Load & Check##
#################################

lhz r12, 0 (r12) #Load Halfword (Item Probability) from Item Table
cmpwi r12, 0x0 #Compare Item Probability Value to 0
beq- no_go #If Item's Probability is 0, we know you cannot get the item for that position for the current in-race room size. Jump to no_go label

################################################
##Locate Your 'Positional Row' On Game's Table##
################################################

add r23, r4, r3 #Add r3 and r4 together. You are now at the green shell halfword for your current position on the game's item table

##############################################################
##Locate Your Exact Item Prob. Halfword Spot on Game's Table##
##############################################################

add r12, r11, r23 #Add r23 and r11 (Item value) to get exact item's halfword prob. location on the game's table

###############################
##Max Item Probability (7FFF)##
###############################

li r11, 0x7FFF #Load 0x7FFF into r11

#######################################################################
##Execute Code; Store 7FFF to Item's Probability Spot on Game's Table##
#######################################################################

sth r11, 0 (r12) #Store halfword of r11 (Maxed Out Item Prob.) to exact spot in Game's Table. Code now executed!

############################
##No_Go Label; Default ASM##
############################

no_go:
cmpwi r0, 0 #Default ASM

#

##################
###END ASSEMBLY###
##################



Source (4th ASM; restore latest revision of Game's Table. Code de-activated.):
####################
###START ASSEMBLY###
####################

#

#############################
##Loop Store Address Config##
#############################

addi r11, r4, -0x2 #Add -0x2 to mem location of r4, store result into r11. The mem location on r11 will be exactly -0x2 away from the very first halfword for the item table which is the halfword for 1st place Green Shell probability

####################################
##Item Table Mem 81 Address Config##
####################################

lis r12, 0x8165 #Set 1st half address from where the current item table will be restored

###############################
##Count Register (CTR) Config##
###############################

li r23, 0xE4 #Load E4 in r17, there are a total of E4 halfwords for the entire item probability table
mtctr r23 #Copy r23's value to the PowerPC dedicated count register

###################
##De_crement Loop##
###################

de_crement:
lhzu r23, 0x0002 (r12) #First, load the first halfword of the backed up item table, increase mem location by 0x2 every time this ASM is done to load the next halfword of the backed up table
sthu r23, 0x0002 (r11) #First, store the current halfword backed up item probability value to the halfword value location of the current edited table. The address will increase by 0x2 every time this ASM is done so each halfword it in its own space.
bdnz+ de_crement #Subtract 1 from the CTR every time this loop is done. If the CTR is not equal to zero, jump back to beginning of de_crement loop

###############
##Default ASM##
###############

cmpwi r0, 0 #Default ASM

#########################################
##Notes about using r23 w/o restoration##
#########################################

##The default ASM writes to r23 after this whole code is executed, so it is safe for use w/o restoration##

#

##################
###END ASSEMBLY###
##################



Code creator: Vega
Code credits: XeR (address founder of 2nd, 3rd and 4th ASMs)
Reply
#2
This code seems to break down on tracks where special probability tables are used. The effects are two:
- You always get the same items in the same positions (ex. getting a Star in 4th on TF, or getting stuck with Green Shells in 9th on MT)
- Boxes and crates give out random items
Reply
#3
(06-13-2020, 12:21 AM)Vega Wrote: An issue with Wiimmfi security/patches then. This code has been tested into the ground for months. Wiimmfi has undergone a lot of changes in the past half year.

It may be time to put a Wiimmfi disclaimer about general code usage somewhere.
Im the biggest bot can u pleasse teach me how to put these codes on my iso for use online? I have not a clue and ive been interested to learn for the past year now
Reply
#4
This will help you.
https://mkwii.com/showthread.php?tid=36
Reply
#5
(06-17-2020, 01:10 PM)1superchip Wrote: This will help you.
https://mkwii.com/showthread.php?tid=36
haha sorry i meant perma patch on my wii disk
Reply
#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
#7
I love looking back at my old codes and see how awful they were. Not just from a code usage standpoint but from Assembly optimization (more in the field of execution speed than compiled length).

Btw Unnamed, do you have a Discord?
Reply
#8
Yes I have, I am also in the MKW-SP server (I saw you are there too), but if needed I can post it here aswell.
Reply
#9
Sent a friend request.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)