Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

      1. Events
    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Zetsu

[C#] Vehicle MemoryAddress

Recommended Posts

Zetsu

Hey!

 

I need a hint with this code

Vehicle vehicle = player.CurrentVehicle;IntPtr vehPtr = vehicle.MemoryAddress;// Following needs unsafe context (/unsafe)Int16 susp = *(Int16* )(vehPtr + 0x7A2);

Actually, it doesn't work because there are some invalid arguments and declarations (like vehicle.MemoryAddress into IntPtr type. MemAdd... is INT). Also, I have problems when I compile. Using an "unsafe" function stops me from building solution. What I want to do is to create a function which helps me to change gear and acceleration (I preffer C#).

 

What's missing?

Share this post


Link to post
Share on other sites
unknown modder

Hey!

 

I need a hint with this code

Vehicle vehicle = player.CurrentVehicle;IntPtr vehPtr = vehicle.MemoryAddress;// Following needs unsafe context (/unsafe)Int16 susp = *(Int16* )(vehPtr + 0x7A2);

Actually, it doesn't work because there are some invalid arguments and declarations (like vehicle.MemoryAddress into IntPtr type. MemAdd... is INT). Also, I have problems when I compile. Using an "unsafe" function stops me from building solution. What I want to do is to create a function which helps me to change gear and acceleration (I preffer C#).

 

What's missing?

use Int16 susp = *(Int16*)((vehPtr + 0x7A2).ToPointer());.

Then make sure the function is marked as unsafe, or the block is in an unsafe block.

Finally in project settings make sure Allow Unsafe Code is checked.

Share this post


Link to post
Share on other sites
Zetsu

 

Hey!

 

I need a hint with this code

Vehicle vehicle = player.CurrentVehicle;IntPtr vehPtr = vehicle.MemoryAddress;// Following needs unsafe context (/unsafe)Int16 susp = *(Int16* )(vehPtr + 0x7A2);

Actually, it doesn't work because there are some invalid arguments and declarations (like vehicle.MemoryAddress into IntPtr type. MemAdd... is INT). Also, I have problems when I compile. Using an "unsafe" function stops me from building solution. What I want to do is to create a function which helps me to change gear and acceleration (I preffer C#).

 

What's missing?

use Int16 susp = *(Int16*)((vehPtr + 0x7A2).ToPointer());.

Then make sure the function is marked as unsafe, or the block is in an unsafe block.

Finally in project settings make sure Allow Unsafe Code is checked.

 

I'll see that. And how do I change the value of 0x7A2 (which is current gear actually)? I can't see any INT argument here defining the gear.

Share this post


Link to post
Share on other sites
ikt

The same way you read it - *(Int16*)(vehPtr + 0x7A2) = val;

Not sure if C# requires a .ToPointer() too here.

  • Like 1

Share this post


Link to post
Share on other sites
CamxxCore

 

Hey!

 

I need a hint with this code

Vehicle vehicle = player.CurrentVehicle;IntPtr vehPtr = vehicle.MemoryAddress;// Following needs unsafe context (/unsafe)Int16 susp = *(Int16* )(vehPtr + 0x7A2);

Actually, it doesn't work because there are some invalid arguments and declarations (like vehicle.MemoryAddress into IntPtr type. MemAdd... is INT). Also, I have problems when I compile. Using an "unsafe" function stops me from building solution. What I want to do is to create a function which helps me to change gear and acceleration (I preffer C#).

 

What's missing?

use Int16 susp = *(Int16*)((vehPtr + 0x7A2).ToPointer());.

Then make sure the function is marked as unsafe, or the block is in an unsafe block.

Finally in project settings make sure Allow Unsafe Code is checked.

 

 

Why use unsafe code?

 

Marshal.ReadInt16 works fine :p

  • Like 1

Share this post


Link to post
Share on other sites
Zetsu

I solved that... Now I got in game and nothing happens, even if my mod is telling me that I'm in 3rd gear, LeeFixSpeedometer tells me 1,2, depending on acceleration. Something missing?

 

I'm looking at this hash
lOhfgi.jpg

 

Code:

veh = player.CurrentVehicle;Int32* vehPtr = veh.MemoryAddress;*(Int16*)(vehPtr + 0x7A0) = 3;

Share this post


Link to post
Share on other sites
ikt

0x7A0? Try reading 0x7A2.

 

Also try my manual transmission's debug thingy

Share this post


Link to post
Share on other sites
Zetsu

0x7A0? Try reading 0x7A2.

 

Also try my manual transmission's debug thingy

 

Both return 0 without modifying them

Share this post


Link to post
Share on other sites
Zetsu

Oh crap, wait. So, i can't convert int* to IntPtr.

 

8rYBze.jpg

 

To get it working I replaced with Int32 (vehPtr variable). veh.MemoryAddress returns a int* result

Share this post


Link to post
Share on other sites
leftas

The error clearly states that there is an explicit cast, not implicit. Just do this

short* currentVehPointer = veh.MemoryAddress;short* currentGear = currentVehPointer + 0x7A0;*currentGear = 3;

Anyway, you need to nop specific code, so your gear wouldn't be overwritten. And just a friendly note: GTA V only supports gear from 0 to 7, inclusive.

 

All the best,
Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
Zetsu

The error clearly states that there is an explicit cast, not implicit. Just do this

 

short* currentVehPointer = veh.MemoryAddress;short* currentGear = currentVehPointer + 0x7A0;*currentGear = 3;

Anyway, you need to nop specific code, so your gear wouldn't be overwritten. And just a friendly note: GTA V only supports gear from 0 to 7, inclusive.

 

All the best,

Paul.

 

Thanks, buut...

 

kzIrgC.jpg

 

And i knew top gear was 7 :) I have modded a "1000HP" Supra. Thanks for that, anyway.

Share this post


Link to post
Share on other sites
leftas

Ugh, explicit means (short*)veh.MemoryAddress.

So you do like this

short* currentVehPointer = (short*)veh.MemoryAddress;short* currentGear = currentVehPointer + 0x7A0;*currentGear = 3;

All the best,

Paul.

Share this post


Link to post
Share on other sites
ikt

Cast it? Unless you make currentVehPtr an int*.

Share this post


Link to post
Share on other sites
leftas

Cast it? Unless you make currentVehPtr an int*.

What do you mean ?

Share this post


Link to post
Share on other sites
Zetsu

And agaain, nothing happens. I'd like to switch to C++, but I get cancer trying to understand some little things and fail when I build solution. Also, In @ikt's scripts, he uses different types. (uint64_t for memory address, to get the memory address, that function returns a uintptr_t and so on..).

Share this post


Link to post
Share on other sites
unknown modder

And agaain, nothing happens. I'd like to switch to C++, but I get cancer trying to understand some little things and fail when I build solution. Also, In @ikt's scripts, he uses different types. (uint64_t for memory address, to get the memory address, that function returns a uintptr_t and so on..).

uint64_t and uintptr_t are the same thing

  • Like 1

Share this post


Link to post
Share on other sites
leftas

And agaain, nothing happens. I'd like to switch to C++, but I get cancer trying to understand some little things and fail when I build solution. Also, In @ikt's scripts, he uses different types. (uint64_t for memory address, to get the memory address, that function returns a uintptr_t and so on..).

Please be exact with "nothing happens". Gear haven't changed up ? The offset still only returns 0 ? C++ and C# won't change a thing when editing memory with pointers.

 

All the best,

Paul

Share this post


Link to post
Share on other sites
ikt

 

Cast it? Unless you make currentVehPtr an int*.

What do you mean ?

 

Just what you said, casting it to a short*.

 

Or, using the same type as veh.MemoryAddress; so you don't need a cast, so int* currentVehPointer = veh.MemoryAddress;

Edited by ikt

Share this post


Link to post
Share on other sites
leftas

 

 

Cast it? Unless you make currentVehPtr an int*.

What do you mean ?

 

Just what you said, casting it to a short*.

 

Or, using the same type as veh.MemoryAddress; so you don't need a cast, so int* currentVehPointer = veh.MemoryAddress;

 

Why use short anyway? The address won't fit in a short.

 

Pointers are pointers, they are different type. And gear is a byte long only, so casting currentGear to it would seem logical, though it really doesn't matter either you use int or short, because game reads only from 0-255.

Back to pointers: in c# terms the short type is only one byte, but when it becomes a pointer(short*), sizeof(short*) is 4/8 bytes depending on used architecture of the program. Because pointer is a variable holding an address and address in x64 is 8 bytes and in x32 is 4 bytes.

 

All the best,

Paul

Edited by leftas
  • Like 1

Share this post


Link to post
Share on other sites
ikt

[...]

Pointers are pointers, they are different type. And gear is a byte long only, so casting currentGear to it would seem logical, though it really doesn't matter either you use int or short, because game reads only from 0-255.

Back to pointers: in c# terms the short type is only one byte, but when it becomes a pointer(short*), sizeof(short*) is 4/8 bytes depending on used architecture of the program. Because pointer is a variable holding an address and address in x64 is 8 bytes and in x32 is 4 bytes.

 

All the best,

Paul

Yeah, I misinterpreted it initially and I removed the last part in my post when I realized my mistake, while you were posting.

  • Like 1

Share this post


Link to post
Share on other sites
Zetsu

Thank you all :)) I'm giving up. Anything I do doesn't work, so left it. I owe you a beer.

Share this post


Link to post
Share on other sites
ikt

What doesn't work precisely? The gear isn't set? You do need to realize you need to kill the automatic downshifting/upshifting in GTA, or continously loop the gear setting.

 

You can also try to change vehicle health, which sticks and shouldn't have a dozen instructions changing it continuously.

  • Like 1

Share this post


Link to post
Share on other sites
Zetsu

What doesn't work precisely? The gear isn't set? You do need to realize you need to kill the automatic downshifting/upshifting in GTA, or continously loop the gear setting.

 

You can also try to change vehicle health, which sticks and shouldn't have a dozen instructions changing it continuously.

 

That's the problem. Killing automatic down/upshifting. Right now I have a paid project which I have to finish fast and I will try again after I finish this.

I've noticed that GTA systems sucks. I attached to E key to turn the engine on (just to see if my mod works ok) and after engine goes off, automatically get back on.

Edited by Zetsu

Share this post


Link to post
Share on other sites
Zetsu

Ok, so i've tried in C++ using your source for steering wheel. Still nothing... I'm gonna give up for real right now. It's pathetic.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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