Advertisement
Dwack

MW3 .cfg from HDD

Jan 6th, 2012
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. # Loading raw .cfg files from HDD
  2. # XePatcher v1.1 script v.01
  3. # by Dwack with help from Caboose
  4. # default_mp tu7
  5.  
  6.  
  7. # Basic Concept
  8. # r29 = .cfg name
  9. # Use CreateFile and ReadFile to get raw file data
  10. # pass that addr back to the original function
  11. # will need to use sprintf to add "GAME:\\" to filename
  12. # "GAME:\\%s"
  13. # need to extract .cfg files from mem/.ff and put on HDD
  14. # if file is not found reverts back to .ff to load it
  15.  
  16. ## Script File
  17.  
  18. .set branchToHook, 0x82286510
  19. .set hookStart, 0x82572E58
  20. .set createFile, 0x824DF430
  21. .set getFileSize, 0x824E0E30
  22. .set readFile, 0x824DF628
  23. .set closeHandle, 0x824DF3E8
  24. .set saveGPRLR27, 0x8254A4F4
  25. .set restGPRLR27, 0x8254A544
  26. .set sprintf, 0x8254B9E8
  27. .set malloc, 0x825571E8 # ? does this even alloc
  28. .set stringGAME, 0x82027E0C
  29. .set loc_82286544, 0x82286544
  30. .set originalBranch, 0x821F10B0
  31.  
  32. .globl _start
  33. _start:
  34.  
  35. # =======================================================
  36. # Patch String
  37. # =======================================================
  38. .long stringGAME
  39. .long(9f-0f)/4
  40. 0:
  41. .string "GAME:\\%s"
  42. .byte 0
  43. .align 2
  44. 9:
  45.  
  46. # =======================================================
  47. #
  48. #
  49. # =======================================================
  50. # Create branch to hook code
  51. # =======================================================
  52. .long branchToHook
  53. .long (9f - 0f)/4
  54. 0:
  55. bl (hookStart - branchToHook)
  56. cmpwi %r3, 0
  57. bne (loc_82286544 - ( branchToHook + 8))
  58. mr %r3, %r29
  59. bl ( originalBranch - (branchToHook + 16))
  60. 9:
  61.  
  62. # =======================================================
  63. #
  64. #
  65. # =======================================================
  66. # Hook code
  67. # =======================================================
  68. .long hookStart
  69. .long (9f - 0f)/4
  70.  
  71. 0:
  72.  
  73. # =======================================================
  74. # Setup : Save
  75. # =======================================================
  76. mfspr %r12, %LR
  77. bl (saveGPRLR27 - (hookStart + 4))
  78. stwu %r1, -0x190(%r1)
  79. mr %r27, %r3 # alloc'd mem
  80. # =======================================================
  81. # sprintf
  82. # =======================================================
  83. nop
  84. nop
  85. lis %r4, stringGAME@h # game:\\%s
  86. ori %r4, %r4, stringGAME@l
  87. mr %r5, %r29 # .cfg name
  88. addi %r3, %r1, 0x40
  89. bl ( sprintf - (hookStart + 40))
  90. # =======================================================
  91. # CreateFile
  92. # =======================================================
  93. lis %r4, -0x8000
  94. li %r5, 0
  95. li %r6, 0
  96. li %r7, 3
  97. li %r8, 0x80
  98. li %r9, 0
  99. addi %r3, %r1, 0x40
  100. bl (createFile - (hookStart + 72))
  101. mr %r30, %r3
  102. cmpwi cr6, %r3, -1
  103. beq cr6, fail_restore_return
  104. # =======================================================
  105. # GetFileSize
  106. # =======================================================
  107. li %r4, 0
  108. mr %r30, %r3
  109. bl (getFileSize - (hookStart + 96))
  110. # =======================================================
  111. # Malloc
  112. # not needed - using mem alloc'd by game
  113. # =======================================================
  114. nop #mr %r31, %r3
  115. nop #bl ( malloc - (hookStart + 104))
  116. # =======================================================
  117. # ReadFile
  118. # =======================================================
  119. nop #mr %r28, %r3
  120. mr %r4, %r27 # buffer
  121. li %r7, 0
  122. addi %r6, %r1, 0x30
  123. mr %r5, %r3 # size
  124. mr %r3, %r30 # handle
  125. bl ( readFile - (hookStart + 132))
  126. cmpwi cr6, %r3, -1
  127. beq cr6, fail_restore_return
  128. # =======================================================
  129. # CloseHandle
  130. # =======================================================
  131. mr %r3, %r30
  132. bl ( closeHandle - (hookStart + 148))
  133. # =======================================================
  134. # Pass : Restore GPR : Return
  135. # =======================================================
  136. nop
  137. mr %r5, %r27
  138. mr %r3, %r27
  139. addi %r1, %r1, 0x190
  140. b (restGPRLR27 - (hookStart + 168))
  141. # =======================================================
  142. # Fail : Restore GPR : Return
  143. # =======================================================
  144. fail_restore_return:
  145. li %r3, 0
  146. mr %r4, %r27
  147. lis %r5, 1
  148. ori %r5, %r5, 0x8000
  149. addi %r1, %r1, 0x190
  150. b (restGPRLR27 -(hookStart + 192))
  151. 9:
  152.  
  153. # =======================================================
  154. # End Patches
  155. # =======================================================
  156. .long 0xFFFFFFFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement