haroohie-club / NitroPacker

A utility for (un)packing NDS ROMs as well as patching their ARM9 and overlays
GNU General Public License v3.0
19 stars 2 forks source link

AutoLoadEntry Argument out of range exception #4

Closed axel7083 closed 9 months ago

axel7083 commented 9 months ago

Description

When using the NitroPacker with Super Mario 64DS, the extract works perfectly. However the patch-arm9 is problematic.

Reproduce

(1) I use a vanilla SM64DS rom, without any patch, fully vanilla, region europe. (2) NitroPackerunpack -r .\EUROPE.nds -o out -p sm64ds (3) I copy the out/arm9.bin to asm_sample (4) NitroPackerunpack patch-arm9 -i asm_sample -o arm9-out -a 0x2058D80 -d latest

Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'value')
   at HaroohieClub.NitroPacker.Patcher.Nitro.CRT0.AutoLoadEntry..ctor(Byte[] data, UInt32 offset) in C:\Users\axels\Documents\github\dsi\NitroPacker\HaroohieClub.NitroPacker.Patcher\Nitro\CRT0.cs:line 68
   at HaroohieClub.NitroPacker.Patcher.Nitro.ARM9..ctor(Byte[] data, UInt32 ramAddress, UInt32 moduleParamsOffset) in C:\Users\axels\Documents\github\dsi\NitroPacker\HaroohieClub.NitroPacker.Patcher\Nitro\ARM9.cs:line 59
   at HaroohieClub.NitroPacker.Patcher.Nitro.ARM9..ctor(Byte[] data, UInt32 ramAddress) in C:\Users\axels\Documents\github\dsi\NitroPacker\HaroohieClub.NitroPacker.Patcher\Nitro\ARM9.cs:line 27
   at HaroohieClub.NitroPacker.Cli.PatchArm9Command.Invoke(IEnumerable`1 arguments) in C:\Users\axels\Documents\github\dsi\NitroPacker\HaroohieClub.NitroPacker.Cli\PatchArm9Command.cs:line 57
   at Mono.Options.CommandSet.Run(IEnumerable`1 arguments)
   at HaroohieClub.NitroPacker.Cli.Program.Main(String[] args) in C:\Users\axels\Documents\github\dsi\NitroPacker\HaroohieClub.NitroPacker.Cli\Program.cs:line 18

Running the program in debug mode give me the following AutoLoadEntry is called with the following context/arguments image

Arena lo

I do not think the issue is coming from the Arena lo value but here is some context arround it

For modding we are using the following values inside the symbols9.x

OS_GetInitArenaLo                                                                 = 0x2058D80;

Inside Ghidra, we can see the following at 0x2058D80

image

jonko0493 commented 9 months ago

@axel7083 Interesting! I'll take a look at this shortly and see if I can figure something out. Thanks for the detailed report!

jonko0493 commented 9 months ago

Aight, I've found two issues so far, one with your commands and one with our code.

  1. The ARM9 binary for SM64DS (EU) is compressed, so the command you need to run is NitroPacker unpack -r .\EUROPE.nds -o out -p sm64ds -d to make sure the ARM9 gets decompressed.
  2. Our code is assuming that the entry address for ROMs is 0x2000000 in all cases, which is probably a value I stuck in there when I first wrote the CLI and forgot to change. We need to have users also provide the project file or a starting RAM address themselves as SM64DS's starting RAM address is 0x2004000.

Once these two things are fixed, everything should start working again. :)

axel7083 commented 9 months ago

Aight, I've found two issues so far, one with your commands and one with our code.

  1. The ARM9 binary for SM64DS (EU) is compressed, so the command you need to run is NitroPacker unpack -r .\EUROPE.nds -o out -p sm64ds -d to make sure the ARM9 gets decompressed.
  2. Our code is assuming that the entry address for ROMs is 0x2000000 in all cases, which is probably a value I stuck in there when I first wrote the CLI and forgot to change. We need to have users also provide the project file or a starting RAM address themselves as SM64DS's starting RAM address is 0x2004000.

Once these two things are fixed, everything should start working again. :)

@jonko0493 thanks you so much for taking time ! Amazing job!