Games

Write a simple ASI plugin for GTA San Andreas

Just warning you it will be difficult, but not so scary as it seems.
Let's write a simple plugin, the function of which will be: on pressing the key, give us a bunch of bucks for a rich and happy life! <!--smile:smile-->smile<!--/smile-->
The article is for beginners, experienced coders it will be useless.

More to the point! To get started, download an integrated development environment, a simple program in which programmers create their own miracles. I chose free and fairly comfortable, and most importantly simple - Dev C 5.11.
You can download it here
You can choose anything, such as Code Blocks or Visual Studio C , a matter of taste, I recommend Code Blocks.


I warn you in advance if you are unable to install this program, or to download, then you should not be reading this article.

Run the program, click menu - new ---> project and choose DLL.
Пишем простой ASI плагин


Maintain our project in any pre-created folder, under the name AsiPlugin.
Before us the source code of the project, did not touch, all you need now is a function called DllMain.
Пишем простой ASI плагин


What is DllMain? This is a function that can be called by the game at startup, and consequently, all that you have conceived and executed this piece of code. For our little experiment we will need the following piece of code:


case DLL_PROCESS_ATTACH:
{
// here we will record our action and it will execute.
break;
}



We need to replenish the player's account? Right first to know when we clicked on the button!
I'll give you a template of these functions can be used in the future.


void OnTimer(HWND hwnd, UINT msg, UINT idTimer, DWORD dwTime)
{
if (GetAsyncKeyState(0x47) & 0x8000) // if clicked on G, 0x47 - key code
{
// then run our code
}
}


Codes for keyboard can be found here.
This piece of code will be repeated every time will be checked the state of the key G.

Next, the most complicated. We need the address of the variable that stores the amount of money of the player. With the help of this address, we believe the money our variable and write the new amount.
Go here (here you will find the main address of a variable of the game)

See our address: 0xB7CE50 - [dword] Money.
How to use this, you ask? Explain!

Something to read the amount of money in a variable you need to declare a variable and do the following trick with the pointer to this address:

Many of DWORD = *(DWORD*)0xB7CE50; // we get the money.
*(DWORD*)0xB7CE50 = 1000000; // give money to player

In the end we get the following code:


Many of DWORD = *(DWORD*)0xB7CE50; // how much money the player has?

if(Many<99999999) // if less than 99999999
{
*(DWORD*)0xB7CE50 = 99999999; // then grab yourself a tidy sum
}



Next, we need to start the timer that will run our function and each time ask: if we have pressed the key?
This is done so - SetTimer(0, 0, 200, (TIMERPROC)OnTimer); // 200 is the interval, in milliseconds

In the end we get the following code:


void OnTimer(HWND hwnd, UINT msg, UINT idTimer, DWORD dwTime)
{
if (GetAsyncKeyState(0x47) & 0x8000) // if pressed G
{

Many of DWORD = *(DWORD*)0xB7CE50; // get the amount of money

if(Many<99999999) // if less money 99999999
{
*(DWORD*)0xB7CE50 = 99999999; // then pick yourself a bunch of bucks
}
}
}



BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{

switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
SetTimer(0, 0, 200, (TIMERPROC)OnTimer); // start our timer
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
case DLL_THREAD_ATTACH:
{
break;
}
case dll_thread_detach are:
{
break;
}
}

return TRUE;
}


Now we have to compile our program and to try it in the game. I just want to draw attention. Select the 32 bit compiler in Dev C , otherwise our plugin will not work.
See the picture how to do it and what to click to compile.
Пишем простой ASI плагин


It turned out without errors? If Yes, then go to the folder with our project and find the DLL file that we have. Rename the extension to ASI and throw in the game folder. Important! Don't forget to set AsiLoader or CLEO 4.
That's all. Start the game and press G. All work? Well done, congratulations!
Ask what's next? Answer: learn programming, maybe you'll make a modding guru, but maybe steeper. <!--smile:smile-->smile<!--/smile-->
Those who have failed, give plugin AsiPlugin.rar and the source code of the project lesson.rar.

Useful links:
Coding books can be downloaded here.
the Address and function Gta San Andreas, there you can find database for IDA, which is a lot of interesting things. How to use IDA, I'm afraid we need a separate article.


Thank you for your attention, hope you liked the article! Good luck to everyone!
p.s: If the article will be of interest to you, the following article will teach you how to use GTA and for example to spawn the car.

The article is exclusive to the site Gamemodding.net when you copy material, you must provide a link to the website.
391
0
31
Like:  31
smalloff
smalloff

Published on 13 May 2016

To favorites
Share
Share:
Information
There are no comments yet. Your comment will be first.
Information
You must be registered to leave a comment on this publication.

Site rules и privacy policy

© 2012-2024 GameModding.com All rights reserved.