My code is stopping after a couple of minutes

int main()
{
while(TRUE)
{

Sleep(0);
info();
if(myaddr5 == 0 && pointed2 == 1 && myaddr6 == 0 && myaddr7 == 0)
shoot();
if(pointed == 1 && pointed2 == 1 && pointed3 == 1)
shoot();
}

}

It works fine for a couple of minutes but then the code will just not work anymore, is there something with sleep(0)? Because if I use Sleep(1); it works fine but its too slow
Without knowing what's happening in info() and shoot(), it's hard to say. There might be a resource leak in one of those functions.

EDIT: And please use code tags when posting code here.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void info(void)
{		
	ZeroMemory(&myaddr2, sizeof(myaddr2));
	ZeroMemory(&myaddr5, sizeof(myaddr5));
	ZeroMemory(&myaddr7, sizeof(myaddr7));
	ZeroMemory(&myaddr6, sizeof(myaddr6));
	HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);		
	int myaddr = FindPointerAddr(hProc, point2, 5, offset5, offset6, offset7, offset8, offset9); 
	int myaddr3 = FindPointerAddr2(hProc, point, 5, offset0, offset1, offset2, offset3, offset4); 
	int myaddr10 = FindPointerAddr(hProc, point3, 4, offset11, offset12, offset13, offset14); 
	int myaddr11 = FindPointerAddr(hProc, point4, 5, offset15, offset16, offset17, offset18, offset19); 
	GetWindowThreadProcessId(hWnd, &proc_id);
	ReadProcessMemory(hProc,(LPCVOID)(myaddr), &myaddr2, 5, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(myaddr3), &myaddr5, 5, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(myaddr10), &myaddr6, 5, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(myaddr11), &myaddr7, 5, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(pointer), &pointed, 2, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(pointer2), &pointed2, 2, NULL);
	ReadProcessMemory(hProc,(LPCVOID)(pointer3), &pointed3, 2, NULL);
} 


1
2
3
4
5
6
void shoot()
{ 
	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	Sleep(1);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}


Sorry for not using code tags. Thats what is inside the code
Last edited on
Bump
Yeah... idk if sleep(0) is valid. the number in the parenthesis is the milliseconds you want to sleep for, you're essentially sleeping for 0 milliseconds (afaik)
before even opening the thread I saw sleep(0) and thought, wtf?
just use sleep(1) or remove sleep altogether


edit: from microsoft site
"A value of zero causes the thread to relinquish the remainder of its time slice to any other thread that is ready to run. If there are no other threads ready to run, the function returns immediately, and the thread continues execution."

also, the sleep in your shoot function should stop the cpu from running at 100%, so just remove sleep from main
Last edited on
I did try removing sleep it didnt help it stops for some random reason :(
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
I'm no expert on Windows programming, but just looking at the name, of this function, I'd guess you're leaking resources here.

Think about it: every time you call info(), you're opening a new process. I don't see anywhere in your program that you're closing the process again. Obviously, at some point, you're going to have opened more processes than your computer can handle, and the program will be terminated.

Edit: OK, looks like I was wrong about creating processes. But I still suspect there's a resource leak somewhere.

Edit 2: But checking the documentation for OpenHandle, it says this:

When you are finished with the handle, be sure to close it using the CloseHandle function.

Seriously, it took me 30 seconds to look this up. Why are you using API functions without first reading up on how to use them properly?
Last edited on
Thank you mikeyboy, I'm an idiot that's why I am using api functions without looking them up proerply
Topic archived. No new replies allowed.