Help with ASM through Bean's CT-Code engine
#1
So i'm working on a battle project that will add many new features to battle mode (inspired by CTGP)
And one of the features that I want to add is a mode called "No mercy" mode. I have completed the coin runners portion where you lose all your coins when hit once (through minigame.kmg edits) and now, I am working on a balloon battle version, where you will die instantly, lose a point, and respawn, (similar to when your last balloon is popped) regardless of the amount of balloons you have. 

Anyway, I generated a code for this: 

Lose all of your balloons after being hit once
c2865c70  00000002
38000000  981d03c4
60000000  00000000


ASM version: 
li r0, 0; /*r0 contains the amount of balloons a player has. Set it to 0 so that the next time a player is hit, trigger the same effects as when they're hit with one balloon left */
stb r0, 964(r29); /*The original instruction after a player is hit, stores the value of r0 into the memory address referenced by r29 + 0x03C4*/
nop;

I tested it through gecko, and it works! However, I want to make this work through Bean's CT-code engine, as it will greatly help me organize the new features i'm adding instead of adding 20 different options in Riivolution. However, there seems to be an issue. 
The very first instruction I create is always replaced by another, and I am unsure why. For example;

My sourcecode to implement this using Bean's MOD engine in ct-code:

[Image: Code.PNG]
The values:
[Image: PROVIDE.PNG]

This is what I see in dolphin once the new ct-code is executed:
[Image: dolphin1.PNG]
^ Perfect, just like my code says.
[Image: dolphin2.PNG]
^ Nearly perfect... but my li r0, 0 instruction is replaced by subi rtoc, rtoc?


Everything is fine and dandy, the instruction at 0x80865c70 branches to 0x80002348 successfully, but this is where the problem comes in. The instruction "li r0, 0" is replaced by "subi rtoc, rtoc, 1691" and i'm not sure why. Everything else beneath this works perfectly, and it's just as I coded it in perfect order. The problem is the "subi rtoc, rtoc, 1691" causes the game to crash, but thats not supposed to be there in the first place. I tried replacing this instruction with my original "li, r0, 0" through dolphin, and bam: code works perfectly!

So to sum it up, any idea why this "subi rtoc, rtoc, 1691" replaces my original "li r0, 0" instruction, and how I could fix this?
Reply
#2
That's an issue with the ct-code engine, or the source you wrote for the ct-code is breaking some rule. Unfortunately, I have no experience with the ct-code stuff. Considering the fact that the RTOC is never meant to be used in any cheat code, I'm shocked the engine even allowed the output of the RTOC at all. Your ASM is all correct though, ofc.
Reply
#3
You could find and set a flag that only activates when the battle loads, then use that flag like this:


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#Set flag at XXXXXXXX address (I'm just using 80830A08 as an example)#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#~~~~~~~~~~~#
#Inject > 80830A08#
#~~~~~~~~~~~#

lis r12, 0x8157
stb r3, 0x0284 (r28) #Example Vanilla Instruction
stw r12, 0 (r12) #Store r12's value as a flag for later

Then, write the main code like this:

#~~~~~~~~~~~#
#Inject > 80865C70#
#~~~~~~~~~~~#

lis r12, 0x8157
bl grab_address #The Branch-Link will Dynamically grab the address of our "li r0, 0" instruction no matter the circumstance.
grab_address:
li r0, 0
lhz r12, 0 (r12) #Grab flag from Mem81
cmplwi r12, 0
beq no_overwrite #Branch past our overwrite if Flag is not set.
mflr r12 #Copy the address from Link Register (The "li r0, 0" instruction address) to Register 12
lis r11, 0x3800 #Load the value 0x38000000 (This is a "li r0, 0" instruction) into Register 11
stw r11, 0 (r12) #Store Register 11's value into the address specified by Register 12 + an offset of 0 (Overwrite "subi rtoc, rtoc, 1691" with "li r0, 0")
no_overwrite:
stb r0, 964(r29) #Vanilla Instruction


Let me know if this helps. If you want to try what I put down, just find an address that only reads when a Battle is loaded and/or running, and set a flag there.
Super Mario Eclipse, what Super Mario Sunshine could've been.
Reply
#4
I finally got it to work, but in an odd way lol. Since the game replaces my first line of code with some other random instruction, i started experimenting with it. Depending on the instruction you put as the first line, the “replacement” will change as well (e.g. li r0, 0 turns into subi rtoc, rtoc... but if i were to write subi r2,r1, 9, this will be replaced with subi r4, r4, 1707 in game)
So I changed the first instruction to subi r2,r1, 9, THEN i put the li r0,0 instruction after. As expected: the subi instruction was replaced and my li r0, 0 instruction now loads. It works fine now!

Of course, I realize this is obviously not the best solution since the game is still inserting a random instruction (in this case, subi r4,r4, 1707) which might affect the game and break something later, but i’ll keep seeing what’ll happen. After a few battles testing this out, nothing seems wrong at all

Thanks for your help, I will definitely look into setting a flag and replacing the subi rtoc instruction, JoshuaMK. I’m still very much a beginner in ASM so i’ll be needing the practice Tongue

Edit; This doesn’t seem to be an issue with the CT-code engine. I looked at the generated file using a hex editor and my li r0 instruction was indeed there, at the correct address. The instruction is replaced once the game loads I assume. Most likely could be my own inexperience in using the engine properly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)