|
| 1 | +[dpad-jump_v288] |
| 2 | +moduleMatches = 0x659C782E |
| 3 | + |
| 4 | +Lp_Utl_getCurSceneId = 0x028C67EC |
| 5 | + |
| 6 | +.origin = codecave |
| 7 | +state: |
| 8 | + .char 0 |
| 9 | +screen_x: |
| 10 | + .short 1080 ; LEFT |
| 11 | + .short 1080 ; UP |
| 12 | + .short 1080 ; RIGHT |
| 13 | + .short 1170 ; DOWN |
| 14 | +screen_y: |
| 15 | + .short 130 ; LEFT |
| 16 | + .short 290 ; UP |
| 17 | + .short 450 ; RIGHT |
| 18 | + .short 625 ; DOWN |
| 19 | + |
| 20 | +perform: |
| 21 | + mflr r0 ; Push LR and important registers to the stack |
| 22 | + stwu r1, -0x10(r1) |
| 23 | + stw r31, 0xC(r1) |
| 24 | + stw r30, 0x8(r1) |
| 25 | + stw r29, 0x4(r1) |
| 26 | + stw r0, 0x14(r1) |
| 27 | + |
| 28 | + mr r31, r4 |
| 29 | + |
| 30 | + lis r30, state@hi |
| 31 | + ori r30, r30, state@l |
| 32 | + lbz r30, 0x0(r30) |
| 33 | + |
| 34 | + bl import.vpad.VPADGetTPCalibratedPoint |
| 35 | + mr r29, r3 |
| 36 | + |
| 37 | + bl Lp_Utl_getCurSceneId ; Check if this is being called during a match |
| 38 | + cmpwi r3, 7 |
| 39 | + beq perform_touch |
| 40 | + cmpwi r3, 12 ; Or Recon |
| 41 | + bne perform_exit ; If not, then exit |
| 42 | + |
| 43 | +perform_touch: |
| 44 | + cmpwi r30, 0 |
| 45 | + beq perform_exit ; Exit if state is 0 (no DPAD pressed) |
| 46 | + subi r30, r30, 1 ; state should be the array index + 1 (since 0 is reserved for no DPAD pressed) |
| 47 | + mulli r30, r30, 2 ; Multiply by 2 for the screen arrays (.short) |
| 48 | + |
| 49 | + lis r3, screen_x@hi |
| 50 | + ori r3, r3, screen_x@l |
| 51 | + lhzx r3, r3, r30 |
| 52 | + |
| 53 | + lis r4, screen_y@hi |
| 54 | + ori r4, r4, screen_y@l |
| 55 | + lhzx r4, r4, r30 |
| 56 | + |
| 57 | + ; Perform a fake touch on the gamepad |
| 58 | + sth r3, 0x0(r31) ; VPADTouchData.x |
| 59 | + sth r4, 0x2(r31) ; VPADTouchData.y |
| 60 | + |
| 61 | + li r3, 1 |
| 62 | + li r4, 0 |
| 63 | + sth r3, 0x4(r31) ; VPADTouchData.touched |
| 64 | + sth r4, 0x6(r31) ; VPADTouchData.validity |
| 65 | + |
| 66 | +perform_exit: |
| 67 | + mr r3, r29 ; Return result from VPADGetTPCalibratedPoint |
| 68 | + lwz r0, 0x14(r1) ; Restore registers from stack |
| 69 | + mtlr r0 |
| 70 | + lwz r31, 0xC(r1) |
| 71 | + lwz r30, 0x8(r1) |
| 72 | + lwz r29, 0x4(r1) |
| 73 | + addi r1, r1, 0x10 |
| 74 | + blr |
| 75 | + |
| 76 | +check_input: |
| 77 | + mflr r0 ; Push LR and important registers to the stack |
| 78 | + stwu r1, -0x10(r1) |
| 79 | + stw r31, 0xC(r1) |
| 80 | + stw r30, 0x8(r1) |
| 81 | + stw r0, 0x14(r1) |
| 82 | + |
| 83 | + mr r31, r4 |
| 84 | + |
| 85 | + bl import.vpad.VPADRead |
| 86 | + mr r30, r3 |
| 87 | + |
| 88 | + lwz r3, 0x0(r31) ; VPADStatus.hold |
| 89 | + lis r4, 0x0000 |
| 90 | + ori r4, r4, 0x8000 ; VPAD_BUTTON_A |
| 91 | + li r5, 0 ; Set to 0 to avoid removing input (happens at set_state) |
| 92 | + and r6, r3, r4 |
| 93 | + cmpw r6, r4 |
| 94 | + bne check_input_reset |
| 95 | + |
| 96 | + li r4, 0x0800 ; VPAD_BUTTON_LEFT |
| 97 | + and r5, r3, r4 |
| 98 | + cmpwi r5, 0 |
| 99 | + li r4, 1 |
| 100 | + bne check_input_set_state |
| 101 | + |
| 102 | + li r4, 0x0200 ; VPAD_BUTTON_UP |
| 103 | + and r5, r3, r4 |
| 104 | + cmpwi r5, 0 |
| 105 | + li r4, 2 |
| 106 | + bne check_input_set_state |
| 107 | + |
| 108 | + li r4, 0x0400 ; VPAD_BUTTON_RIGHT |
| 109 | + and r5, r3, r4 |
| 110 | + cmpwi r5, 0 |
| 111 | + li r4, 3 |
| 112 | + bne check_input_set_state |
| 113 | + |
| 114 | + li r4, 0x0100 ; VPAD_BUTTON_DOWN |
| 115 | + and r5, r3, r4 |
| 116 | + cmpwi r5, 0 |
| 117 | + beq check_input_reset |
| 118 | + li r4, 4 |
| 119 | + |
| 120 | +check_input_set_state: |
| 121 | + bl Lp_Utl_getCurSceneId ; Check if this is being called during a match |
| 122 | + cmpwi r3, 7 |
| 123 | + beq _check_input_set_state |
| 124 | + cmpwi r3, 12 ; Or Recon |
| 125 | + bne check_input_exit ; If not, then exit |
| 126 | + |
| 127 | +_check_input_set_state: |
| 128 | + lwz r3, 0x0(r31) |
| 129 | + sub r5, r3, r5 ; Disable DPAD input to avoid sending unnecessary signals (very hacky, doesn't work too well) |
| 130 | + stw r5, 0x0(r31) |
| 131 | + |
| 132 | + lis r3, state@hi |
| 133 | + ori r3, r3, state@l |
| 134 | + stb r4, 0x0(r3) |
| 135 | + |
| 136 | +check_input_exit: |
| 137 | + mr r3, r30 ; Return result from VPADRead |
| 138 | + lwz r0, 0x14(r1) ; Restore registers from stack |
| 139 | + mtlr r0 |
| 140 | + lwz r31, 0xC(r1) |
| 141 | + lwz r30, 0x8(r1) |
| 142 | + addi r1, r1, 0x10 |
| 143 | + blr |
| 144 | + |
| 145 | +check_input_reset: |
| 146 | + li r4, 0 |
| 147 | + b check_input_set_state |
| 148 | + |
| 149 | +0x28D0F30 = bl check_input ; VPADRead |
| 150 | +0x286FD38 = bl perform ; VPADGetTPCalibratedPoint |
| 151 | + |
0 commit comments