Source Code Improved Chat/Command Based Hack

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Lovelace

Jr.Coder
Full Member
Nobleman
Oct 23, 2015
83
938
5

Tired of buttons and hotkeys to enable/disable your hacks? Ever wanted to create your own chat/command based hack? Then you're in the right thread. I had 2 hours of spare time, so I thought I should code a portable command handler class. Instead of using long ass if-else if statements, this method which I'm about to show you is much cleaner. Let's get started.

This structure will hold the commands.

C++:
struct Command_t
{
	int hash;
	int index;
	int max_input;
	void* address;
	std::string msg1, msg2; // encrypt these if you want
};
This function will allocate memory for the new command you would like to add. I'll explain later how to use this function.

C++:
size_t cmdSize;
std::vector<Command_t> Commands;

void AddCommand(LPCSTR cmd, LPCSTR msg1, LPCSTR msg2, const int max, void* var, std::vector<std::string> vec = {})
{
	size_t sz = vec.size();
	for (size_t i = 0; i < sz + 1; i++)
	{
		Commands.push_back(Command_t());
		std::string temp = cmd;
		if (sz > 0) temp += " " + vec[i];
		int hash = hashCode(temp);
		Commands[cmdSize].hash = hash;
		Commands[cmdSize].address = var;
		Commands[cmdSize].index = sz > 0 ? i + 1 : 0;
		Commands[cmdSize].max_input = sz == 0 ? max : 0;
		if (msg1 != NULL) Commands[cmdSize].msg1 = msg1;
		if (msg2 != NULL) Commands[cmdSize].msg2 = msg2;
		cmdSize = Commands.size();
		if (i >= sz - 1) break;
	}
}
This is where all the magic happens. This function is responsible for toggling the hack and setting the values.

C++:
void ProcessCommand(LPCSTR cmd)
{
	int hash = hashCode(cmd);
	int value = 0;
	int space = 0;
	bool isDigit = true;
	const char* pCmd = cmd;
	std::string message;

	for (size_t i = 0; i < strlen(cmd); i++)
		if (cmd[i] == ' ') space = i;
	if (space == 0)
		isDigit = false;
	else
	{
		pCmd += space;
		for (size_t i = 1; i < strlen(pCmd); i++)
			if (!(pCmd[i] >= '0' && pCmd[i] <= '9')) {
				isDigit = false;
				break;
			}
		if (isDigit)
			value = atoi(pCmd + 1);
	}

	for (size_t i = 0; i < cmdSize; i++)
	{
		if (isDigit && Commands[i].max_input > 0)
		{
			std::string strCmd(cmd);
			ReplaceString(strCmd, pCmd, "");
			hash = hashCode(strCmd);

			if (hash == Commands[i].hash)
			{
				if (value >= 0 && value <= Commands[i].max_input)
				{
					*(int*)Commands[i].address = value;

					message = value ? Commands[i].msg1 : Commands[i].msg2;
					ReplaceString(message, "<VALUE>", pCmd + 1);
					std::cout << message.c_str() << std::endl; // CChat::PrintChatMessage(message.c_str(), "", INFO, true, false, PINK);

					return;
				}
			}
		}
		else if (hash == Commands[i].hash && Commands[i].max_input == 0)
		{
			if (Commands[i].index == 0)
				value = !(*(char*)Commands[i].address);
			else
				value = Commands[i].index - 1;
			
			// I don't think anyone would be using an array that has 255 elements LOL
			*(char*)Commands[i].address = value;

			message = value ? Commands[i].msg1 : Commands[i].msg2;
			ReplaceString(message, "<VALUE>", pCmd + 1);
			std::cout << message.c_str() << std::endl; // CChat::PrintChatMessage(message.c_str(), "", INFO, true, false, PINK);

			return;
		}
	}
}
Some functions we'll be using.

C++:
void ReplaceString(std::string& str, const char* toFind, const char* toReplace)
{
	while (str.find(toFind) != std::string::npos)
		str.replace(str.find(toFind), strlen(toFind), toReplace);
}

int hashCode(std::string text)
{
	int hash = 0, strlen = text.length();

	if (strlen == 0)
		return 0;

	for (int i = 0; i < strlen; i++)
		hash = (31 * hash) + (toascii(text[i]));

	return hash;
}
AddCommand Function Usage

C++:
void AddCommand(LPCSTR cmd, LPCSTR msg1, LPCSTR msg2, const int max, void* var, std::vector<std::string> vec)
1. Standard usage (for toggling the hack on and off):

C++:
AddCommand("/aim", "Aimbot on.", "Aimbot off.", 0, &aim);
2. Command with input value:

C++:
AddCommand("/speed", "Speed set(<VALUE>).", "Speed hack off.", 5, &speed);
3. Command with set of elements:

C++:
AddCommand("/aim rifle", "Rifle aimbot target set to '<VALUE>'.", "Rifle aimbot target set to '<VALUE>'.", 0, &aim_rifle_target, { "head", "spine" });
Notice the tags, "<VALUE>", in the messages? That tag will display the value which the user entered. In case 2, if the user entered, "/speed 3", it will print "Speed set (3)." And in case 3, if the user entered, "/aim rifle spine", it will print "Rifle aimbot target set to 'spine'.".

Here's a ready to test c&p C++ source: https://pastebin.com/Z5xGagCU
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,205
78,998
2,400
This is wicked cool I will definately use this someday :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods