Jump to content

Help reading address in simple Cleo Script GTA SA


Recommended Posts

sergiope

Hi! I'm new to coding in CLEO and I'm trying to make a simple script for GTA SA that replaces a variable's value with another one.

My goal is to change CJ’s preset car during a race. When the script is triggered, the car he's in should be converted into the accepted race car.

I've identified the correct memory addresses using Cheat Engine, and can modify it succesfully there, but I can't get a script to read and replace the variable.
The memory addresses are these two: 
gta_sa.exe+64AD88 -> 0x00A4AD88  - Indicates the car CJ is in
gta_sa.exe+648F60 -> 0x00A48F60 - Determines race car

Here's my code:

 

{$CLEO .cs}
nop

:START
wait 0
if 
  Player.IsPlaying($PLAYER_CHAR)  // Checks if the game is active
goto_if_false @START
if 
  0ADC: test_cheat "CAR"    // Detects the "CAR" cheat
goto_if_false @START
0A8D: 1@ = read_memory 0x00A4AD88 size 4 virtual_protect 0 // Reads the value from 0x00A4AD88
0A8C: write_memory 0x00A48F60 size 4 value 1@ virtual_protect 0 // Writes to 0x00A48F60
goto @START

When I enter the cheat code, I get this error:
Invalid pointer '0x0' input argument #1 "address" in script 'change_car.cs' at offset {40} - 0A8D: READ_MEMORY Script suspended.

I've successfully written a value to memory before, but reading always gives me this kind of error.

How can I fix this?

Thanks!

Edited by sergiope
forgot to mention the game
sergiope
4 minutes ago, vladvo said:

It won't work. You can't switch car by changing just 4 bytes of code. There's a lot lot more stuff required and still it won't be "seamless".

Thanks for the answer! When I manually change the value in Cheat Engine, it works—at least for the purpose I’m aiming for. I’ve tested it multiple times, and it doesn’t affect my gameplay (although, as you mentioned, there may be buggy things I can’t see but I’d still like to try it that way). If I hardcode the value in a CLEO script, it also works, but I can’t input the value I need. I’m just looking for a way to read and store that value (0x00A4AD88) through code instead of doing it manually. Isn't that possible?

OrionSR

You've got an odd mix of older SB syntax and SBL syntax, which is probably causing issues with the param order of the read_memory command. Pick an edit mode (SBL in SB4 is recommended) and stick with the syntax of that mode.

$PLAYER_CHAR is specific to older edit modes, in SBL it's $player1. It is best not to use opcode ID numbers in SBL mode; it limits the formatting options, which can lead to errors like yours.

 

If you are still having trouble, please specify your SB version and the edit mode you are using.

 

Edited by OrionSR
sergiope
48 minutes ago, OrionSR said:

You've got an odd mix of older SB syntax and SBL syntax, which is probably causing issues with the param order of the read_memory command. Pick an edit mode (SBL in SB4 is recommended) and stick with the syntax of that mode.

$PLAYER_CHAR is specific to older edit modes, in SBL it's $player1. It is best not to use opcode ID numbers in SBL mode; it limits the formatting options, which can lead to errors like yours.

 

If you are still having trouble, please specify your SB version and the edit mode you are using.

 

That solved the problem! I had mixed old SB code snippets with SBL syntax, since I didn't know much. After converting everything to SBL syntax it works fine now. Thanks a lot for your help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.