Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- GTA Analog Stick Patch
- Copyright (C) 2016, TheFloW
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <pspsdk.h>
- #include <pspkernel.h>
- #include <pspctrl.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <string.h>
- #include <systemctrl.h>
- PSP_MODULE_INFO("gta_patch", 0x0007, 1, 0);
- #define MAKE_JUMP(a, f) _sw(0x08000000 | (((u32)(f) & 0x0FFFFFFC) >> 2), a);
- #define MAKE_CALL(a, f) _sw(0x0C000000 | (((u32)(f) >> 2) & 0x03FFFFFF), a);
- #define REDIRECT_FUNCTION(a, f) \
- { \
- u32 func = a; \
- _sw(0x08000000 | (((u32)(f) >> 2) & 0x03FFFFFF), func); \
- _sw(0, func + 4); \
- }
- #define MAKE_DUMMY_FUNCTION(a, r) \
- { \
- u32 func = a; \
- if (r == 0) \
- { \
- _sw(0x03E00008, func); \
- _sw(0x00001021, func + 4); \
- } \
- else \
- { \
- _sw(0x03E00008, func); \
- _sw(0x24020000 | r, func + 4); \
- } \
- }
- #define HIJACK_FUNCTION(a, f, ptr) \
- { \
- u32 func = a; \
- static u32 patch_buffer[3]; \
- _sw(_lw(func), (u32)patch_buffer); \
- _sw(_lw(func + 4), (u32)patch_buffer + 8);\
- MAKE_JUMP((u32)patch_buffer + 4, func + 8); \
- _sw(0x08000000 | (((u32)(f) >> 2) & 0x03FFFFFF), func); \
- _sw(0, func + 4); \
- ptr = (void *)patch_buffer; \
- }
- #define MAX_VALUE 0xFF
- #define CENTER 0x80
- #define DEADZONE 0x20
- #define FACTOR 1.2f
- STMOD_HANDLER previous;
- int getRx() {
- char rx = *(char *)(0x08803000 + 0);
- rx -= CENTER;
- if (rx < -DEADZONE || rx > DEADZONE)
- return (int)((float)rx * FACTOR);
- return 0;
- }
- int getRy() {
- char ry = *(char *)(0x08803000 + 1);
- ry = MAX_VALUE - ry;
- ry -= CENTER;
- if (ry < -DEADZONE || ry > DEADZONE)
- return (int)((float)ry * FACTOR);
- return 0;
- }
- int cameraLeft() {
- char rx = *(char *)(0x08803000 + 0);
- rx -= CENTER;
- if (rx < -DEADZONE)
- return 1;
- return 0;
- }
- int cameraRight() {
- char rx = *(char *)(0x08803000 + 0);
- rx -= CENTER;
- if (rx > DEADZONE)
- return 1;
- return 0;
- }
- int cameraUp() {
- char ry = *(char *)(0x08803000 + 1);
- ry -= CENTER;
- if (ry < -DEADZONE)
- return 1;
- return 0;
- }
- int cameraDown() {
- char ry = *(char *)(0x08803000 + 1);
- ry -= 0x80;
- if (ry > DEADZONE)
- return 1;
- return 0;
- }
- // combat
- // limit up: "lwc1 $fpr12, -29048($gp);"
- // limit down "lwc1 $fpr12, -29052($gp);"
- // speed up: "lwc1 $fpr14, -29064($gp);"
- // speed down: "lwc1 $fpr14, -29064($gp);"
- // free run
- /*
- // l trigger
- if (a0 == 4)
- // circle
- if (a0 == 0)
- // square
- if (a0 == 1)
- // up
- if (a0 == 2)
- // down
- if (a0 == 3)
- */
- int OnModuleStart(SceModule2 *mod) {
- char *modname = mod->modname;
- u32 text_addr = mod->text_addr;
- if (strcmp(modname, "GTA3") == 0) {
- // Redirect camera movement
- REDIRECT_FUNCTION(text_addr + 0x00294C88, getRx);
- REDIRECT_FUNCTION(text_addr + 0x00294D88, getRy);
- // Redirect gun aim movement
- REDIRECT_FUNCTION(text_addr + 0x00294A54, getRx);
- REDIRECT_FUNCTION(text_addr + 0x00294B58, getRy);
- // Allow using L trigger when walking
- _sw(0, text_addr + 0x00293550);
- _sw(0, text_addr + 0x002935B4);
- // Force L trigger value
- _sw(0x240AFFFF, text_addr + 0x000EDC38);
- sceKernelDcacheWritebackAll();
- } else if (strcmp(modname, "main") == 0) {
- // Patch camera in combat mode
- MAKE_CALL(text_addr + 0x0005203C, cameraLeft);
- MAKE_CALL(text_addr + 0x00052074, cameraRight);
- MAKE_CALL(text_addr + 0x000520AC, cameraDown);
- MAKE_CALL(text_addr + 0x000520E4, cameraUp);
- // Patch camera in climbing mode
- MAKE_CALL(text_addr + 0x00066104, cameraLeft);
- MAKE_CALL(text_addr + 0x00066128, cameraRight);
- MAKE_CALL(text_addr + 0x00066170, cameraDown);
- MAKE_CALL(text_addr + 0x0006614C, cameraUp);
- // Patch camera in running mode
- MAKE_CALL(text_addr + 0x00071294, cameraLeft);
- MAKE_CALL(text_addr + 0x0007133C, cameraRight);
- MAKE_CALL(text_addr + 0x000713EC, cameraDown);
- MAKE_CALL(text_addr + 0x00071478, cameraUp);
- // Allow left camera movement
- _sw(0, text_addr + 0x000712AC);
- _sw(0x50000007, text_addr + 0x000712F4);
- // Allow right camera movement
- _sw(0, text_addr + 0x00071354);
- _sw(0x50000007, text_addr + 0x0007139C);
- // Force L trigger value
- _sw(0, text_addr + 0x00052030);
- _sw(0x10000005, text_addr + 0x000660E4);
- _sw(0, text_addr + 0x00071E98);
- _sw(0x10000021, text_addr + 0x0007158C);
- sceKernelDcacheWritebackAll();
- }
- if (!previous)
- return 0;
- return previous(mod);
- }
- int module_start(SceSize args, void *argp) {
- previous = sctrlHENSetStartModuleHandler(OnModuleStart);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement