;I've written this code backwards to give you an idea of what might help you.
;The next line is the LAST line of the sample, the line after is the second-to-last, etc.
;Also, all of this code is fake and none of these functions are real. It's just an example.
bl GX2MakeGraphicsTerrible
;Right, here's the function we want to mess with.
;From the docs available from WiiUBrew and other places, we know that it takes 1 argument - a number.
;For the sake of this explanation, let's call it "level"
;We want to set level to 3.
;At this point, we can say for sure that r3 must have level in it.
;This is because r3 is the first argument to a function, and
;the docs say that the first argument to GX2MakeGraphicsTerrible is level.
;So where is r3 set? Let's look look backwards in the code.
addi r3, r5, 1
;This takes the value in r5, adds 1, and puts the result in r3.
;We know that r3 is level. Therefore, r5 + 1 = level.
;At this point, we don't know what is in r3 and it doesn't really matter to us.
;What we have found out is that level = r5 + 1, OR r5 = level - 1.
;So, what sets r5?
mr r5, r30
;This moves the value of r30 into r5.
;Now we know that at this point in the program, r30 contains level - 1.
;Again, we don't know what r5 is at this point.
;So far we've been pretty lucky and all the related commands have been right next to each other.
;However, this won't happen all the time. Here is a whole bunch of unrelated code that deals with something else.
;What we need to be looking for is r30 (level - 1).
;Keep in mind that functions and whatnot can change a register and it will stay changed afterwards.
beq error_message ;If the last two numbers we compared are equal (eq), break (b) to error_message
cmpwi r3, 0 ;Compare these two numbers
bl GX2IsEverythingOkay
li r4, 420 ;r4 = 420, technically impossible (the number 420 is too big)
addi r3, r5, r6 ;r3 = r5 + r6
;As I said, completely unrelated.
mr r30, r3
;Ah-ha! It's r30!
;As you know, this moves the value of r3 into r30.
;So, at this point:
;We don't know what r5 or r30 are
;We know that r3 is level - 1
bl OSReadConfigFile
;Here's another function. From the docs, we know it takes a string (char*, but again, for another day)
;and reads a config file from that location, returning what it found.
;So, where did that value it returned go? We know that it should be in r3. This is where it all comes together.
;r3 = level - 1.
;r3 is also the value returned by OSReadConfigFile.
;Since we can't have two values in one register, we can reason that level - 1 = value returned by OSReadConfigFile. We're close!
;At this point, all we know is that r3 contains the location of our config file.
li r3, 0xBABECAFE ; "/meta/0141/f99e/6969/theyll-never-find-this/notconfig.config.exe.jpg"
;Here's where r3 is set. It's being set to the location of a string, which IDA helpfully finds for us and puts as a comment.
;So, we know that level - 1 is stored at a config file at the path above. We can change a config file!
;Since we wanted to set level to 3, we should put 2 in the config file (remember how the program adds 1?).