QuestionMultiple while loops

Posts 1–6 of 6 · Page 1 of 1
Multiple while loops
I stumbled across a little problem and i have no idea how to fix it.

I want to create a memory hack, let's say godmode and unlimited ammo.

I would do something like this:

Code:
void keys()
{
    while(1){
        if(GetAsyncKeyState(VK_F1)){
            god =! god;
            godMode();
            Sleep(300);
        }else if(GetAsyncKeyState(VKF2)){
            ammo =! ammo;
            unlAmmo();
            Sleep(300);
        }
    }
}

void godMode()
{
    while(god){
        WriteProcessMemory(proc,(LPVOID)address,&health,sizeof(health),NULL);
    }
}

void unlAmmo()
{
    while(ammo){
        WriteProcessMemory(proc,(LPVOID)address,&uammo,sizeof(uammo),NULL);
    }
}
My problem is that i can't run multiple while loop at once, so the whole code is a bunch of garbage. Could someone please give me a hint what to do instead?
Using logic would solve the problem. You've already got an infinite while loop (outside of main, idk why since your loop doesn't do anything except monitor the keys)

Code:
void keys()
{
    while(1){
        if(GetAsyncKeyState(VK_F1)){
            god =! god;
            Sleep(300);
        }else if(GetAsyncKeyState(VKF2)){
            ammo =! ammo;
            Sleep(300);
        }
	if (ammo) {
		WriteProcessMemory(proc,(LPVOID)address,&uammo,sizeof(uammo),NULL);
	}
	if (god) {
		WriteProcessMemory(proc,(LPVOID)address,&health,sizeof(health),NULL);
	}
    }
}
Just throw your WPM calls in your main while loop when the state is true for the corresponding call. Alternatively you could delve into threads and learn how to multi-thread programs.
Code:
void keys()
{
    while(1){
        if(GetAsyncKeyState(VK_F1)){
            god =! god;
            Sleep(300);
        }else if(GetAsyncKeyState(VKF2)){
            ammo =! ammo;
            Sleep(300);
        }
	if (ammo) {
		WriteProcessMemory(proc,(LPVOID)address,&uammo,sizeof(uammo),NULL);
	}
	if (god) {
		WriteProcessMemory(proc,(LPVOID)address,&health,sizeof(health),NULL);
	}
    }
}

I already figured that out by myself, but that would cause other problems and it doesn't look very nice. I'll take a look at multi-threads, thanks for that
Quote Originally Posted by Callme? View Post
I already figured that out by myself, but that would cause other problems and it doesn't look very nice. I'll take a look at multi-threads, thanks for that
What do you mean with "other problems" - "it doesn't look very nice"? You should explain what are your needs.
For threads synchronization mechanism you could take a look to Mutex class. A Mutex is a synchronization object to make able a thread to access mutually to a resource.
Quote Originally Posted by maestro1994 View Post
What do you mean with "other problems" - "it doesn't look very nice"? You should explain what are your needs.
For threads synchronization mechanism you could take a look to Mutex class. A Mutex is a synchronization object to make able a thread to access mutually to a resource.
I solved my problem with multi-threading(ThreadProc,CreateThread), but thanks anyway
#solved
Code:
void keys()
{
    while(1){
        if(GetAsyncKeyState(VK_F1) & 1){
            god =! god;
        }else if(GetAsyncKeyState(VKF2) & 1){
            ammo =! ammo;
        }

        godMode();
        unlAmmo();
        Sleep(300);
    }
}

void godMode()
{
        if (god) {
             WriteProcessMemory(proc,(LPVOID)address,&health,sizeof(health),NULL);
        }
}

void unlAmmo()
{
    if (ammo){
        WriteProcessMemory(proc,(LPVOID)address,&uammo,sizeof(uammo),NULL);
    }
}
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us