Quantcast

Jump to content

» «
Photo

[ C++ ] Calling functions of gta v

Best Answer Zemanez, 02 September 2017 - 10:01 PM

I'd highly recommend learning GTA modding through A.B's native trainer. That'll give you an idea on how to call natives and how they work etc. It's part of the Scripthook SDK so comes with the sources for you to look over. An ASI is just a DLL with a different extension so it should help you anyway. 

 

You can't call GTA functions through a hash without the native invoker. Your DLL injection worked due to how DLLs function, but the code wouldn't have been executed because the game doesn't know what you're wanting to do. 

 

In this case, you were missing the native invoker to call the function directly (there are alternative means of doing this but since those can be used for Online modding - won't be discussed here). If you look through A.B's Native Trainer, you'll find how the invoker works. In essence, you find the block of memory where all the natives begin and store that address (this is done in the scripthook.dll file). When you call a native, the invoker is given the hash of the native you are calling and finds the corresponding address in memory before calling it with the args given. It's quite a complicated system to be honest. 

 

There's no books as far as I can tell (I'm interested in this sort of thing, but haven't found any books on it) but it's an interesting method of modding.

Go to the full post


5 replies to this topic
buridan
  • buridan

    Player Hater

  • Members
  • Joined: 01 Sep 2017
  • Russia

#1

Posted 01 September 2017 - 06:09 PM Edited by buridan, 01 September 2017 - 07:38 PM.

I have a Injector programm and DLL. In my DLL file I have description of native functions of gta with adresses. But when i call functions nothink happens.

P.S. Addreses of function I took there -> http://www.dev-c.com/nativedb/

CODE: https://pastebin.com/YaA4nf1j


Zemanez
  • Zemanez

    Certified Code Wizard!

  • Members
  • Joined: 01 May 2015
  • United-Kingdom

#2

Posted 01 September 2017 - 11:17 PM

Well, to start you aren't using the scripthook which, as the name suggests, 'hooks' onto the game's script thread and passes it commands. You're just pushing code into the game when the DLL is first injected + attached which is doing nothing in this instance (you're basically injecting a string with a type. The game doesn't know what you're doing and it's never executed as a result). You should also have just told it to run main() or some other function/method instead of putting your code directly into the attach statement (good programming practice!) but that won't be executed either without some form of thread being told to execute it. 

 

Secondly you aren't using a native invoker so the game doesn't know what you're doing, so even if you had a hook - it doesn't know what those natives are because you aren't calling the invoker, which means any natives you do manage to execute somehow, will never actually be executed because the invoker is never used.  

 

Thirdly those aren't addresses for the natives - they're hashes. You can't call natives via hash. The first long string is the hash of the "original native" (as in day 1 game release) which the scripthook 'maps' onto the most recent native hash (otherwise known as a "crosshashmap" because it crosses the original native hash with the most recent one so it can be called). 

 

Why aren't you just using A.B's scripthook dev menu? It's a functional menu with source code that you can look over to see how to properly execute natives. 


buridan
  • buridan

    Player Hater

  • Members
  • Joined: 01 Sep 2017
  • Russia

#3

Posted 02 September 2017 - 11:22 AM Edited by buridan, 02 September 2017 - 04:32 PM.

Well, to start you aren't using the scripthook which, as the name suggests, 'hooks' onto the game's script thread and passes it commands. You're just pushing code into the game when the DLL is first injected + attached which is doing nothing in this instance (you're basically injecting a string with a type. The game doesn't know what you're doing and it's never executed as a result). You should also have just told it to run main() or some other function/method instead of putting your code directly into the attach statement (good programming practice!) but that won't be executed either without some form of thread being told to execute it. 

 

Secondly you aren't using a native invoker so the game doesn't know what you're doing, so even if you had a hook - it doesn't know what those natives are because you aren't calling the invoker, which means any natives you do manage to execute somehow, will never actually be executed because the invoker is never used.  

 

Thirdly those aren't addresses for the natives - they're hashes. You can't call natives via hash. The first long string is the hash of the "original native" (as in day 1 game release) which the scripthook 'maps' onto the most recent native hash (otherwise known as a "crosshashmap" because it crosses the original native hash with the most recent one so it can be called). 

 

Why aren't you just using A.B's scripthook dev menu? It's a functional menu with source code that you can look over to see how to properly execute natives. 

Okey, I realized that I do not understand everything about this.
I'm very interested to understand how these things work, and how they can be done by myself. Can you give any advice, maybe you know the books on these topics?

If i inject DLL in process thread, and it work(i tested it), how can i call gta5 function by hash?


Zemanez
  • Zemanez

    Certified Code Wizard!

  • Members
  • Joined: 01 May 2015
  • United-Kingdom

#4

Posted 02 September 2017 - 10:01 PM   Best Answer

I'd highly recommend learning GTA modding through A.B's native trainer. That'll give you an idea on how to call natives and how they work etc. It's part of the Scripthook SDK so comes with the sources for you to look over. An ASI is just a DLL with a different extension so it should help you anyway. 

 

You can't call GTA functions through a hash without the native invoker. Your DLL injection worked due to how DLLs function, but the code wouldn't have been executed because the game doesn't know what you're wanting to do. 

 

In this case, you were missing the native invoker to call the function directly (there are alternative means of doing this but since those can be used for Online modding - won't be discussed here). If you look through A.B's Native Trainer, you'll find how the invoker works. In essence, you find the block of memory where all the natives begin and store that address (this is done in the scripthook.dll file). When you call a native, the invoker is given the hash of the native you are calling and finds the corresponding address in memory before calling it with the args given. It's quite a complicated system to be honest. 

 

There's no books as far as I can tell (I'm interested in this sort of thing, but haven't found any books on it) but it's an interesting method of modding.

  • buridan likes this

CamxxCore
  • CamxxCore

    Mark Chump

  • Members
  • Joined: 19 Oct 2013
  • Canada

#5

Posted 02 September 2017 - 10:08 PM

OpenVHook is an open- source Scripthook implementation. Maybe it offers some insight (:

  • ikt and buridan like this

buridan
  • buridan

    Player Hater

  • Members
  • Joined: 01 Sep 2017
  • Russia

#6

Posted 03 September 2017 - 06:13 AM

Guys, thanks for giving the direction and prompting where to start!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users