kwsch / pk3DS

Pokémon (3DS) ROM Editor & Randomizer
https://projectpokemon.org/forums/forums/topic/34377-pk3ds-xyoras-rom-editor-randomizer/
Other
401 stars 150 forks source link

Editing shiny rates causes crashes, regardless of value #126

Closed sora10pls closed 7 years ago

sora10pls commented 7 years ago

Can confirm this is the case for Gen 7, have not tested yet for Gen 6. Process:

Open pk3DS -> Load Pokemon Moon game files -> Run Shiny Rates editor -> Change 8 to 9 -> Move over .code.bin to SD for Luma3DS to read externally -> Run Pokemon Moon -> Game crashes

sora10pls commented 7 years ago

Can confirm the same thing happens for Gen 6.

And while I'm at it, I'm not sure how this editor even saves the number of rerolls... I'll set it to a value of 6000, save and exit the editor, re-open it, and it automatically changed itself from 6000 to 1905.

Would it be possible to make the editor super user friendly and have the user simply enter a shiny rate percentage, and the program would automatically determine the amount of rerolls? A lot of noobs using the tool will find it very confusing, as well as myself if I'm perfectly honest lmao

kwsch commented 7 years ago

Did you recompress it? I'm not familiar with how luma loads the files

https://github.com/kwsch/pk3DS/commit/9eee50d6f35b959e88a97372c7ad080f036607bf enhanced a little to help you calculate a reroll count to specify

the 8 is arbitrary (highest the game does normally via international-masuda), hence perma-1:512 for everything.

Try specifying a lower count; all that's changing is one instruction but idk what could be crashing it.

sora10pls commented 7 years ago

Luma3DS does not require you recompress it for it to be loaded externally.

I've tested multiple different code.bin files edited with pk3DS. In the case of Gen 6, TM/HM edits as well as Mart edits worked; in any event where I edited shiny rates, the game crashed with the newly made code.bin.

I'll try to recompress and report back, though.

kwsch commented 7 years ago

disassembly of X for reference: https://i.snag.gy/L5Rfaz.jpg

sora10pls commented 7 years ago

Recompressing the code.bin and loading the file externally simply leaves the console to endlessly loop the Nintendo 3DS logo when attempting to launch the game.

kwsch commented 7 years ago

Does the Restore Original Rate button allow it to boot again? It should copy the original instruction back.

Could be that the MOVW isn't kosher, maybe need to use the MOV instruction instead.

FA 0E A0 E3 uses the MOV instruction and should set to 4000

sora10pls commented 7 years ago

Restoring original rate does indeed allow the game to properly load without crashes.

kwsch commented 7 years ago

Okay so it properly restores; try the above instruction (use HxD to find the before/after offset it's writing at)

sora10pls commented 7 years ago

Before (number of rerolls = 8): image

After (number of rerolls = 9): image

kwsch commented 7 years ago

Try writing FA 0E A0 E3 instead of 09 00 00 E3 (the 8 rerolls deal was just a default value, not what the game originally did; the game provides an object variable with the count... we just override it). Also, try setting a reroll value that isn't a multiple of 4, and less than 256.

When I did my testing it was all with Citra after the game had loaded; I doubt there's some sort of validity check on just this region and nowhere else.

sora10pls commented 7 years ago

Game launches totally fine after doing so :)

Edit: shiny rate also seems to be modified, as I've run into 6 or so shinies now in Friend Safari, so the value you gave me is working as intended.

sora10pls commented 7 years ago

Setting a reroll value of 147 (not a multiple of 4, less than 256) still caused the game to crash.

This is what it looked like afterwards in HxD: image

sora10pls commented 7 years ago

I can also confirm that the value you gave me earlier (FA 0E A0 E3 instead of 09 00 00 E3) worked with Pokemon Moon as well!

Before (not modified, did not crash): image

After edited with pk3DS (did crash): image

After edited with HxD (did not crash): image

kwsch commented 7 years ago

I don't think the patch actually works correctly; the FA 0E A0 E3 corresponds to MOV R0, #0xFA0 (4000), which should be noticeable after a few encounters.

note to self: @SciresM suggested doing something like LDR R0, [pc, #some_value] to load the value from a fixed offset

sora10pls commented 7 years ago

Shiny rate definitely was modified after writing FA 0E A0 E3 to Moon's code.bin, so it seems that only when it's edited with pk3DS it causes a crash.

If you need me to test anything else, just let me know!

kwsch commented 7 years ago

Ah, it could just be my testing method screwing up :)

cool that it works

I was using http://armconverter.com/ to convert the instructions to hex but was unable to figure out how to convert it to c# for 'compiling' the MOV instruction for these %4 variants... guess they work so I'll figure something out!

sora10pls commented 7 years ago

Glad to hear and to help :+1:

kwsch commented 7 years ago

Added a table of precomputed instructions (~700) to support reroll counts up to ~9000 (which is darn near 100%). https://github.com/kwsch/pk3DS/commit/1f377de7e23ad73dd9175d28335f909d7530fc55

Thanks for the help !

sora10pls commented 7 years ago

My pleasure!

sora10pls commented 7 years ago

Hmm... may have found a bug with latest commit. If the specified number of rerolls is greater than 256, it doesn't save properly. Anything <= 255 is fine, though.

sora10pls commented 7 years ago

Commit f60a981 did indeed fix this :) thanks!