I'm trying to make a while (true) loop inside of a case with a do-while loop but when I put the while (true) in the case the menu doesn't loop back to the console and I need to close the debugger and run it again can someone help me I'm new to c .
Here is my code:
do
{
std::cout << "[0] Quit\n"; // This is Option 0 of the Menu
std::cout << "[1] Infinite Health\n"; // This is Option 1 of the Menu
std::cout << "[2] Infinite Ammo\n"; // This is Option 2 of the Menu
std::cout << "[3] Infinite Rounds\n"; // This is Option 3 of the Menu
std::cin >> choice;
switch (choice) // This is to detect the Choice the User selected
{
case 0:
std::cout << "Why did you even open me to not use me :(\n";
return 0;
case 1:
std::cout << "You Have Activated Infinite Health!\n";
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
break;
case 2:
std::cout << "You Have Activated Infinite Ammo On Primary Weapon!\n";
while (true)
{
int ammo = 500;
WriteProcessMemory(phandle, (LPVOID*)(ammoPtrAddr), &ammo, 4, 0);
}
break;
case 3:
std::cout << "You Have Activated Infinite Rounds On Primary Weapon!";
while (true)
{
int rounds = 200;
WriteProcessMemory(phandle, (LPVOID*)(roundsPtrAddr), &rounds, 4, 0);
}
break;
}
}
while (choice !=0);
CodePudding user response:
Yes it doesn't return, because it is blocking the program.
To solve your problem you could put the loop inside of another thread.
if you include the thread library using:
#include <thread>
You'd then have to define the function that should run:
void keepHealth() {
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
}
You can now execute this function in another thread with:
std::thread task1(keepHealth);
If you want to pass arguments like your handles, you'd have to write them in the function header:
void keepHealth(void* pHandle, void* healthPtrAddress) {
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
}
and pass them like this:
std::thread task1(keepHealth, pHandle, healthPtrAddress);