Results 1 to 6 of 6
  1. #1
    Callme?'s Avatar
    Join Date
    Dec 2015
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    4
    My Mood
    Stressed

    Question 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?

  2. #2
    InunoTaishou's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    The Internet
    Posts
    446
    Reputation
    20
    Thanks
    950
    My Mood
    Relaxed
    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.
    https://www.mpgh.net/forum/signaturepics/sigpic210976_1.gif

  3. The Following User Says Thank You to InunoTaishou For This Useful Post:

    Callme? (02-22-2016)

  4. #3
    Callme?'s Avatar
    Join Date
    Dec 2015
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    4
    My Mood
    Stressed
    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

  5. #4
    maestro1994's Avatar
    Join Date
    Sep 2015
    Gender
    male
    Posts
    95
    Reputation
    10
    Thanks
    13
    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.



  6. #5
    Cosmo_'s Avatar
    Join Date
    Oct 2014
    Gender
    male
    Location
    Los Angeles
    Posts
    126
    Reputation
    13
    Thanks
    19
    My Mood
    Sleepy
    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);
        }
    }

  7. #6
    Callme?'s Avatar
    Join Date
    Dec 2015
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    4
    My Mood
    Stressed
    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

Similar Threads

  1. [Source Code] Spammer, No Timer, Multiple Lines, freeze/unfreeze loop, Registered HotKeys, Sendkeys
    By AngryLeech in forum Visual Basic Programming
    Replies: 1
    Last Post: 10-28-2014, 03:45 PM
  2. [Discussion] For vs. While Loops
    By chickeninabiskit in forum C++/C Programming
    Replies: 19
    Last Post: 08-02-2013, 05:51 AM
  3. [Help] While Loop statement help (not hacking related AT ALL.)
    By JimTheGreat in forum C++/C Programming
    Replies: 3
    Last Post: 06-24-2012, 05:10 PM
  4. [Help] While Loop Does Not Initialize [Solved]
    By Braco22 in forum C++/C Programming
    Replies: 7
    Last Post: 08-31-2011, 02:50 PM
  5. (HELP!) Stopping a While Loop After A Certain Time! (HELP!)
    By Pete8497 in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 21
    Last Post: 08-16-2010, 04:02 PM