Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Loading raw .cfg files from HDD
- # XePatcher v1.1 script v.01
- # by Dwack with help from Caboose
- # default_mp tu7
- # Basic Concept
- # r29 = .cfg name
- # Use CreateFile and ReadFile to get raw file data
- # pass that addr back to the original function
- # will need to use sprintf to add "GAME:\\" to filename
- # "GAME:\\%s"
- # need to extract .cfg files from mem/.ff and put on HDD
- # if file is not found reverts back to .ff to load it
- ## Script File
- .set branchToHook, 0x82286510
- .set hookStart, 0x82572E58
- .set createFile, 0x824DF430
- .set getFileSize, 0x824E0E30
- .set readFile, 0x824DF628
- .set closeHandle, 0x824DF3E8
- .set saveGPRLR27, 0x8254A4F4
- .set restGPRLR27, 0x8254A544
- .set sprintf, 0x8254B9E8
- .set malloc, 0x825571E8 # ? does this even alloc
- .set stringGAME, 0x82027E0C
- .set loc_82286544, 0x82286544
- .set originalBranch, 0x821F10B0
- .globl _start
- _start:
- # =======================================================
- # Patch String
- # =======================================================
- .long stringGAME
- .long(9f-0f)/4
- 0:
- .string "GAME:\\%s"
- .byte 0
- .align 2
- 9:
- # =======================================================
- #
- #
- # =======================================================
- # Create branch to hook code
- # =======================================================
- .long branchToHook
- .long (9f - 0f)/4
- 0:
- bl (hookStart - branchToHook)
- cmpwi %r3, 0
- bne (loc_82286544 - ( branchToHook + 8))
- mr %r3, %r29
- bl ( originalBranch - (branchToHook + 16))
- 9:
- # =======================================================
- #
- #
- # =======================================================
- # Hook code
- # =======================================================
- .long hookStart
- .long (9f - 0f)/4
- 0:
- # =======================================================
- # Setup : Save
- # =======================================================
- mfspr %r12, %LR
- bl (saveGPRLR27 - (hookStart + 4))
- stwu %r1, -0x190(%r1)
- mr %r27, %r3 # alloc'd mem
- # =======================================================
- # sprintf
- # =======================================================
- nop
- nop
- lis %r4, stringGAME@h # game:\\%s
- ori %r4, %r4, stringGAME@l
- mr %r5, %r29 # .cfg name
- addi %r3, %r1, 0x40
- bl ( sprintf - (hookStart + 40))
- # =======================================================
- # CreateFile
- # =======================================================
- lis %r4, -0x8000
- li %r5, 0
- li %r6, 0
- li %r7, 3
- li %r8, 0x80
- li %r9, 0
- addi %r3, %r1, 0x40
- bl (createFile - (hookStart + 72))
- mr %r30, %r3
- cmpwi cr6, %r3, -1
- beq cr6, fail_restore_return
- # =======================================================
- # GetFileSize
- # =======================================================
- li %r4, 0
- mr %r30, %r3
- bl (getFileSize - (hookStart + 96))
- # =======================================================
- # Malloc
- # not needed - using mem alloc'd by game
- # =======================================================
- nop #mr %r31, %r3
- nop #bl ( malloc - (hookStart + 104))
- # =======================================================
- # ReadFile
- # =======================================================
- nop #mr %r28, %r3
- mr %r4, %r27 # buffer
- li %r7, 0
- addi %r6, %r1, 0x30
- mr %r5, %r3 # size
- mr %r3, %r30 # handle
- bl ( readFile - (hookStart + 132))
- cmpwi cr6, %r3, -1
- beq cr6, fail_restore_return
- # =======================================================
- # CloseHandle
- # =======================================================
- mr %r3, %r30
- bl ( closeHandle - (hookStart + 148))
- # =======================================================
- # Pass : Restore GPR : Return
- # =======================================================
- nop
- mr %r5, %r27
- mr %r3, %r27
- addi %r1, %r1, 0x190
- b (restGPRLR27 - (hookStart + 168))
- # =======================================================
- # Fail : Restore GPR : Return
- # =======================================================
- fail_restore_return:
- li %r3, 0
- mr %r4, %r27
- lis %r5, 1
- ori %r5, %r5, 0x8000
- addi %r1, %r1, 0x190
- b (restGPRLR27 -(hookStart + 192))
- 9:
- # =======================================================
- # End Patches
- # =======================================================
- .long 0xFFFFFFFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement