1

I have 2 void functions and a main func.

But since first function has while(true) it works always and due to that second is not working. How to make it work all together at the same time?

   void shoot()
{
    *(DWORD*)(val.gameModule + offsets.ForceAttack, 5);
    Sleep(5000);
    *(DWORD*)(val.gameModule + offsets.ForceAttack, 4);
}

void bunny()
{


    val.gameModule = (DWORD)GetModuleHandle("client_panorama.dll");

    std::cout << (GetModuleHandle("client_panorama.dll")) << std::endl;;
    val.localPlayer = *(DWORD*)(val.gameModule + offsets.lplayer);
    while (true)
    {
        if (bunnyON == 1);
        else
            return;
        val.flag = *(BYTE*)(val.localPlayer + offsets.flags);
        if (isMoving())
            if (GetAsyncKeyState(VK_SPACE) && val.flag & (1 << 0))
                * (DWORD*)(val.gameModule + offsets.jump) = 6;
    }
}




int main()
{


    bunny();
    shoot();
}
`
9
  • 3
    Short answer: Threads Commented Dec 11, 2019 at 14:08
  • @NathanOliver-ReinstateMonica so i have to put all my functions to a thread?
    – Win
    Commented Dec 11, 2019 at 14:09
  • 1
    Run each function in it's own thread. This will require changes though since you need to make the code thread safe. Commented Dec 11, 2019 at 14:11
  • To solve this, you should use multithreading. This is an advanced C++ topic, which I suggest you learn later if you are a newbie. In this case, you need to run one of the functions in a separate thread (1 additional thread is enough since main function is already executed by "main thread").
    – SubMachine
    Commented Dec 11, 2019 at 14:12
  • 3
    Before you start with multi-threading, please, be aware multi-threading is not that easy. Alternatively, you could interleave your functions without threads, i.e. re-organize your code that you can perform one step per call. Then move the endless loop into main() and call shoot_step() and bunny_step() in the loop. Commented Dec 11, 2019 at 14:12

1 Answer 1

1

Try to do this, and check if this is what you need:

#include <thread>

void shoot()
{
    *(DWORD*)(val.gameModule + offsets.ForceAttack, 5);
    Sleep(5000);
    *(DWORD*)(val.gameModule + offsets.ForceAttack, 4);
}

void bunny()
{
    val.gameModule = (DWORD)GetModuleHandle("client_panorama.dll");

    std::cout << (GetModuleHandle("client_panorama.dll")) << std::endl;;
    val.localPlayer = *(DWORD*)(val.gameModule + offsets.lplayer);
    while (true)
    {
        if (bunnyON == 1);
        else
            return;
        val.flag = *(BYTE*)(val.localPlayer + offsets.flags);
        if (isMoving())
            if (GetAsyncKeyState(VK_SPACE) && val.flag & (1 << 0))
                * (DWORD*)(val.gameModule + offsets.jump) = 6;
    }
}

int main()
{
    std::thread t1(bunny);
    std::thread t2(shoot);

    t1.join();
    t2.join();

    return 0;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.