2016-11-16 03:41:59 +01:00
|
|
|
.arm.little
|
|
|
|
.create "build/romfsredir.bin", 0
|
|
|
|
|
2017-04-13 01:03:37 +02:00
|
|
|
.macro addr, reg, func
|
|
|
|
add reg, pc, #func-.-8
|
|
|
|
.endmacro
|
2016-11-16 03:41:59 +01:00
|
|
|
.macro load, reg, func
|
|
|
|
ldr reg, [pc, #func-.-8]
|
|
|
|
.endmacro
|
2017-04-13 01:03:37 +02:00
|
|
|
|
|
|
|
; Patch by delebile
|
2016-11-16 03:41:59 +01:00
|
|
|
|
|
|
|
.arm
|
2017-04-13 01:03:37 +02:00
|
|
|
_start:
|
|
|
|
|
|
|
|
; Jumps here before the fsOpenFileDirectly call
|
2017-04-23 05:40:02 +02:00
|
|
|
_mountArchive:
|
|
|
|
b mountArchive
|
2017-04-13 01:03:37 +02:00
|
|
|
.word 0xdead0000 ; Substituted opcode
|
|
|
|
.word 0xdead0001 ; Branch to hooked function
|
2016-11-16 03:41:59 +01:00
|
|
|
|
2017-04-13 01:03:37 +02:00
|
|
|
; Jumps here before every iFileOpen call
|
|
|
|
_fsRedir:
|
|
|
|
b fsRedir
|
|
|
|
.word 0xdead0002 ; Substituted opcode
|
|
|
|
.word 0xdead0003 ; Branch to hooked function
|
2016-11-16 03:41:59 +01:00
|
|
|
|
2017-04-23 18:44:46 +02:00
|
|
|
; Mounts the archive and registers it as 'lf:'
|
2017-04-23 05:40:02 +02:00
|
|
|
mountArchive:
|
2017-04-13 01:03:37 +02:00
|
|
|
cmp r3, #3
|
2017-04-23 05:40:02 +02:00
|
|
|
bne _mountArchive + 4
|
2017-04-13 01:03:37 +02:00
|
|
|
stmfd sp!, {r0-r4, lr}
|
|
|
|
sub sp, sp, #4
|
2017-04-23 03:11:02 +02:00
|
|
|
load r1, archiveId
|
2017-04-13 01:03:37 +02:00
|
|
|
mov r0, sp
|
|
|
|
load r4, fsMountArchive
|
|
|
|
blx r4
|
|
|
|
mov r3, #0
|
|
|
|
mov r2, #0
|
|
|
|
ldr r1, [sp]
|
2017-04-23 03:11:02 +02:00
|
|
|
addr r0, archiveName
|
2017-04-13 01:03:37 +02:00
|
|
|
load r4, fsRegisterArchive
|
|
|
|
blx r4
|
|
|
|
add sp, sp, #4
|
|
|
|
ldmfd sp!, {r0-r4, lr}
|
2017-04-23 05:40:02 +02:00
|
|
|
b _mountArchive + 4
|
2017-04-13 01:03:37 +02:00
|
|
|
|
|
|
|
; Check the path passed to iFileOpen.
|
|
|
|
; If it is trying to access a RomFS file, we try to
|
2017-04-23 05:40:02 +02:00
|
|
|
; open it from the LayeredFS folder.
|
|
|
|
; If the file cannot be opened, we just open
|
2017-04-13 01:03:37 +02:00
|
|
|
; it from its original archive like nothing happened
|
|
|
|
fsRedir:
|
|
|
|
stmfd sp!, {r0-r12, lr}
|
2017-05-05 20:16:44 +02:00
|
|
|
addr r3, romFsMount
|
|
|
|
bl compare
|
|
|
|
addne r3, pc, #updateRomFsMount-.-8
|
|
|
|
blne compare
|
|
|
|
bne endRedir
|
2017-04-13 01:03:37 +02:00
|
|
|
sub sp, sp, #0x400
|
|
|
|
pathRedir:
|
|
|
|
stmfd sp!, {r0-r3}
|
|
|
|
add r0, sp, #0x10
|
2017-05-05 20:16:44 +02:00
|
|
|
load r3, customPath
|
2017-04-13 01:03:37 +02:00
|
|
|
pathRedir_1:
|
|
|
|
ldrb r2, [r3], #1
|
|
|
|
cmp r2, #0
|
2017-07-05 01:31:04 +02:00
|
|
|
strneh r2, [r0], #2
|
2017-04-13 01:03:37 +02:00
|
|
|
bne pathRedir_1
|
|
|
|
pathRedir_2:
|
|
|
|
ldrh r2, [r1], #2
|
2017-04-23 05:40:02 +02:00
|
|
|
cmp r2, #0x3A ; ':'
|
2017-04-13 01:03:37 +02:00
|
|
|
bne pathRedir_2
|
2017-07-05 01:31:04 +02:00
|
|
|
; Skip a slash if there are two after the mountpoint,
|
|
|
|
; as some games mistakenly have those
|
|
|
|
ldrh r3, [r1, #2]
|
|
|
|
cmp r3, #0x2F ; '/'
|
2017-04-13 01:03:37 +02:00
|
|
|
pathRedir_3:
|
|
|
|
ldrh r2, [r1], #2
|
2017-07-05 01:31:04 +02:00
|
|
|
strneh r2, [r0], #2
|
2017-04-13 01:03:37 +02:00
|
|
|
cmp r2, #0
|
|
|
|
bne pathRedir_3
|
|
|
|
ldmfd sp!, {r0-r3}
|
|
|
|
mov r1, sp
|
2017-04-23 05:40:02 +02:00
|
|
|
bl _fsRedir + 4
|
2017-04-13 01:03:37 +02:00
|
|
|
add sp, sp, #0x400
|
|
|
|
cmp r0, #0
|
|
|
|
|
|
|
|
endRedir:
|
|
|
|
ldmfd sp!, {r0-r12, lr}
|
|
|
|
moveq r0, #0
|
|
|
|
bxeq lr
|
2017-04-23 05:40:02 +02:00
|
|
|
b _fsRedir + 4
|
2017-04-13 01:03:37 +02:00
|
|
|
|
2017-05-05 20:16:44 +02:00
|
|
|
compare:
|
|
|
|
mov r9, r1
|
|
|
|
add r10, r3, #4
|
|
|
|
loop:
|
|
|
|
ldrb r12, [r3], #1
|
|
|
|
ldrb r11, [r9], #2
|
|
|
|
cmp r11, r12
|
|
|
|
bxne lr
|
|
|
|
cmp r10, r3
|
|
|
|
bne loop
|
|
|
|
bx lr
|
|
|
|
|
2016-11-16 03:41:59 +01:00
|
|
|
.pool
|
|
|
|
.align 4
|
2017-04-23 18:44:46 +02:00
|
|
|
archiveName : .dcb "lf:", 0
|
2017-04-23 03:11:02 +02:00
|
|
|
fsMountArchive : .word 0xdead0005
|
|
|
|
fsRegisterArchive : .word 0xdead0006
|
2017-04-23 05:40:02 +02:00
|
|
|
archiveId : .word 0xdead0007
|
2017-05-05 20:16:44 +02:00
|
|
|
romFsMount : .dcb "rom:"
|
|
|
|
updateRomFsMount : .word 0xdead0008
|
2017-04-23 03:11:02 +02:00
|
|
|
customPath : .word 0xdead0004
|
2017-04-13 01:03:37 +02:00
|
|
|
|
|
|
|
.close
|