Quantcast

Jump to content

» «
Photo

ASI not working

3 replies to this topic
ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#1

Posted 15 September 2013 - 10:24 PM

Hey guys, I've wrote an ASI for Vice City but for some reason it isn't working.

 

It's supposed to give the player four wanted stars when starting a new game with a stripped main.

#include "windows.h"

BOOL APIENTRY Dllmain()
{
DWORD address = 0x94AD28; //Ped Pointer
DWORD offset1 = 0x5F4; //Wanted Pointer
DWORD offset2 = 0x0; //Wanted Counter
DWORD newvalue[] = {1200}; //Four Wanted Stars
HANDLE phandle = NULL;
if (DLL_PROCESS_ATTACH)
{
ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
address = address + offset1;
ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
address = address + offset2;
WriteProcessMemory(phandle, (LPVOID)address, (LPVOID) &newvalue, 4, 0);
}
return TRUE;
}

Now, I've tried it without the DLL_PROCESS_ATTACH check but that didn't work either.

 

I'm a real n00b at this stuff, so any help appreciated.

 

Thanks guys.


Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci Racing
  • Joined: 20 Jun 2010
  • None

#2

Posted 17 September 2013 - 03:57 PM Edited by Bad.boy!, 17 September 2013 - 03:57 PM.

It doesn't work because your code is executed when the game starts. You need to hook a (in)game function, so that your code will be executed when the game is loaded. And in your hooked function you should force a pointer on the address you want to modify, instead of using ReadProcessMemory and WriteProcessMemory.

 

I assume that you're trying to learn how to create your own game mods in a real programming language. But it doesn't look like you know the programming language well. You should try to master the language before writing mods in it. Also cleo scripts are a better and easier way to write mods, ASI plugins don't offer much advantages unless you're rewriting bits/parts of the engine.


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci Racing
  • Joined: 19 Aug 2006
  • Unknown

#3

Posted 17 September 2013 - 04:58 PM Edited by Wesser, 17 September 2013 - 05:00 PM.

A bit of clarifications about your newbie code:

  1. C++ is a case-sensitive programming language, thus the name of your entry point is incorrect because of this. The forward declaration of DllMain function is as follows:
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpvReserved);
    
  2. DLL_PROCESS_ATTACH is a constant value declared by #define directive defined somewhere in windows.h. Although it handles a value of 1, if you put it alone as a condition of any control flow, it will be always treated as true, pretty useless. You would rather match such value with dwReasonForCall variable instead to check for a succesful DLL loading as a result of LoadLibrary calling.
  3. No need to call ReadProcessMemory function to get the content of a pointer of the current process. You can simply dereference it through *.

xanser
  • xanser

    Player Hater

  • Members
  • Joined: 12 Sep 2006
  • None

#4

Posted 14 November 2013 - 06:20 AM Edited by xanser, 15 November 2013 - 01:10 AM.

Try this code. Press 0,1,2,3,4,5,6 keys to change wanted level. But it seems, wanted level refresh when you hit any cops/peds

#include "stdafx.h"

bool NewGame = true;
 
DWORD* dwPlrPointer = (DWORD*)0x94AD28;
BYTE* bPlayerBlock;
DWORD* dwWantedPointer;
DWORD* dwWantedLevel;
BYTE* HUDWantedLevel;

void TestPlayer() {
 
	if (*dwPlrPointer)
	{
		if (NewGame)												
		{
			NewGame = false;										
			bPlayerBlock	= (BYTE*)(*dwPlrPointer);	// 0x94AD28 - [pointer] - Player is an instance of CPed Class 
			dwWantedPointer = (DWORD*)(bPlayerBlock+0x5F4);	// +0x5F4 - [pointer] - wanted level pointer
			dwWantedLevel   = (DWORD*)(*dwWantedPointer);	// +0x0   - [4 bytes] - wanted counter 
			HUDWantedLevel  = (BYTE*)dwWantedLevel+0x20;	// +0x20  - [1 byte] - HUD active wanted level 
		}
		if (GetAsyncKeyState('0')&1) *dwWantedLevel=0;		// 0 wanted level if 0 pressed
		if (GetAsyncKeyState('1')&1) *dwWantedLevel=51;		// set 1 star if 1 pressed  (above 50)
		if (GetAsyncKeyState('2')&1) *dwWantedLevel=181;	// set 2 stars if 2 pressed (above 180)
		if (GetAsyncKeyState('3')&1) *dwWantedLevel=551;	// set 3 stars if 3 pressed (above 550)
		if (GetAsyncKeyState('4')&1) *dwWantedLevel=1201;	// set 4 stars if 4 pressed (above 1200)
		if (GetAsyncKeyState('5')&1) *dwWantedLevel=2401;	// set 5 stars if 5 pressed (above 2400)
		if (GetAsyncKeyState('6')&1) *dwWantedLevel=4601;	// set 6 stars if 6 pressed (above 4600)

		*HUDWantedLevel = ((*dwWantedLevel)>50) + 		// add 1 star if true (1 star)
				  ((*dwWantedLevel)>180) + 		// add 1 star if true (2 stars)
				  ((*dwWantedLevel)>550) + 		// add 1 star if true (3 stars)
				  ((*dwWantedLevel)>1200) + 		// add 1 star if true (4 stars)
				  ((*dwWantedLevel)>2400) + 		// add 1 star if true (5 stars)
				  ((*dwWantedLevel)>4600); 		// add 1 star if true (6 stars)
	}
	else NewGame = true;
};
 
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
 
        SetTimer(0,0, 100, (TIMERPROC)TestPlayer);
 
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users