Skip to content

Commit

Permalink
Input detection patch (#4)
Browse files Browse the repository at this point in the history
* Input checker

* Remove the <1> and <2> variants, comment

* add simple tap stuff

* separate custom commands

* ....my bad

* remove original hook, 0x200 for life!

* Version checker command

* how did this not go through????

* tldr we have less code space than i thought
  • Loading branch information
patataofcourse authored Feb 21, 2023
1 parent afdc312 commit 76746a5
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# RHMPatch
A game and file-system redirection patch for Rhythm Heaven Megamix (US version) for 3DS.

## Building
Install armips, place an unmodified code.bin as "original.bin", then run `armips asm/main.s`. You'll find the patched code.bin, now make an IPS patch from the files, and you're done!

## Credits
- Original patches by Neobeo
- Gate game prologue jingle patch by patataofcourse.
- Gate game prologue jingle patch + custom input detection patch by patataofcourse
113 changes: 113 additions & 0 deletions asm/custom_cmds.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
; Jumptable for custom commands

common_cmd_default equ 0x0025c3c0
common_cmd_return equ 0x002613cc

cmd_amount equ 2

.org common_cmd_default
b jt_switchcase

.org pr_end

jt_switchcase:
sub r1, #0x200
cmp r1, #0
blt common_cmd_return
cmp r1, cmd_amount
ldrcc pc, [pc, r1, lsl #2] ; since jt_table is right there
b common_cmd_return
jt_table:
.word input_command
.word version_command
jt_end:

; Registers' values

; r2 - special arg / arg0
; r3 / r5 - cmd args
; r6 - game state

; 0x201 - Quick version check
version_command:
cmp r2, #0
strne r0, [r6, #0x20]
bne common_cmd_return

mov r0, MAJOR_VERSION * 0x100
add r0, r0, MINOR_VERSION
str r0, [r6, #0x20]
b common_cmd_return

; 0x200 - Input checker command
gSaveData equ 0x0054d350
gInputManager equ 0x0054eed0

input_command:
cmp r2, #2
bhi in_null
bcc in_getinput

; 0x200<2>: get simple tap vs buttons mode
push {r0, r1, r3}

; loads from save
ldr r0, =gSaveData
ldr r0, [r0]

; 0x2dc8 (gSaveData->fileData + fileData.isSimpleTap)
mov r1, #0xb7
lsl r1, r1, #6
add r1, r1, #8

; 0x1648 (sizeof(individual save))
mov r2, #0x59
lsl r2, r2, #6
add r2, r2, #8

; 0x7560 (gSaveData->currentFile)
mov r3, #0x75
lsl r3, r3, #8
add r3, #0x60

; final offset: gSaveData->fileData[gSaveData->currentFile].isSimpleTap
ldr r3, [r0, r3]
mul r2, r2, r3
add r2, r2, r1
ldrb r2, [r0, r2]

pop {r0, r1, r3}
in_getinput:
ldr r0, =gInputManager
ldr r0, [r0]
cmp r2, #0
bhi in_touch

; 0x200<0>: check for button input at specified bit
; don't shift by 32 bits or more, that'll always be 0
ldr r1, [r3] ; args[0]
cmp r1, #0x20
bcs in_null

; load input data (u32 bitflags) @ gInputManager->unk4->unk4
ldr r0, [r0, #4]
ldr r0, [r0, #4]

; set condvar to bit number args[0]
lsr r0, r0, r1
and r0, r0, #1
str r0, [r6, #0x20]
b common_cmd_return
in_touch:
; 0x200<1>: check for touchscreen input @ gInputManager->unk8->unkC
ldr r0, [r0, #8]
ldrb r0, [r0, #0xc]
str r0, [r6, #0x20]
b common_cmd_return
in_null:
; set condvar to 0
mov r0, #0
str r0, [r6, #0x20]
b common_cmd_return

.pool
15 changes: 14 additions & 1 deletion patch.asm → asm/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
.arm.little
.open "original.bin", "code.bin", 0x100000

MAJOR_VERSION equ 1
MINOR_VERSION equ 3

; prologue + custom command code start
; putting it before apparently garbles the code and turns it to `b 0` fsr
newCode equ 0x399C00

; custom commands
.include "asm/custom_cmds.s"

.if . > 0x39A000
.error "Custom command code too big"
.endif

openFile equ 0x279E60 ; svc 0x32 (0x08030204)
getSize equ 0x2BC628 ; svc 0x32 (0x08040000)
readFile equ 0x2BC544 ; svc 0x32 (0x080200C2)
Expand Down Expand Up @@ -225,7 +239,6 @@ sdPath: .asciiz "_:/rhmm"
; Prologue jingle patch

gateJingleFunc equ 0x32D678
newCode equ 0x399F00
prologueJingles equ 0x52C9B8

.org gateJingleFunc
Expand Down

0 comments on commit 76746a5

Please sign in to comment.