😎 Don't always PushToConsole

Posts 1–9 of 9 · Page 1 of 1
😎 Don't always PushToConsole
I'm fairly new here and just got some of my own initial hacks working with help from the amazing source of information I've found in the forums. One thing I'm noticing a lot are unnecessary PTC in while loops so I thought I'd call it out since I noticed my CA would crash/exit until I fixed it.

Example of what not to do:

Code:
while(true) {
   PushToConsole("...");
}
Some of this can be mitigated by detecting if the Console shell exists before pushing a command to the LTC. This type of checking is always good:

Code:
void __cdecl PushToConsole( const char* szCmd )
{
	DWORD dwCShell = (DWORD)GetModuleHandleA("CShell.dll");
	if( dwCShell != NULL )
	...

Another case of the never-ending pushes that I see floating around the forums are when you set a flag based on a key-event (or whatever), and then either always push the command to be active or inactive:

Code:
   bool chams = false;

   while(true) {
	// Chams
	if(GetAsyncKeyState(VK_NUMPAD1)&1) {
		chams = !chams;
        }
        ...
	if(chams) {
		PushToConsole("SkelModelStencil 0");
	} else {
		PushToConsole("SkelModelStencil 1");
	}
	Sleep(100);
        ...
}
Those "Sleep" commands can only do so much, but you are essentially constantly pushing commands (either chams-on or chams-off) all the time. Rather, if you want something simple, then just do the command push and flag update on the key event:

Code:
while(true) {
		// Chams
		if(GetAsyncKeyState(VK_NUMPAD1)&1)
		{
			if(chams) {
				PushToConsole("SkelModelStencil 0");
			} else {
				PushToConsole("SkelModelStencil 1");
			}
			chams = !chams;
			Sleep(100);
		}
     ...
}
So far I've seen better hack success and less CA exit/crashes.

On a slight side note, I'm also seeing less exits when doing "Release" quality builds from VS2008 and packing the DLL through UPX.

Anyways, I hope this helps. If not, then... well... hello.

Regards,
--Phot0n
Great Contribution Bro..

+Rep
+Thanks
very very good post
nice.. good thing to know

/thanked
Yes, this is great for reducing lag in hotkey hacks. But how would you do it with a menu? I've been thinking about it for awhile I just haven't quite figured out how to code it.
I posted some code some time ago. You might find it when you search for my posts.
Quote Originally Posted by Phot0n View Post

Code:
while(true) {
		// Chams
		if(GetAsyncKeyState(VK_NUMPAD1)&1)
		{
			if(chams) {
				PushToConsole("SkelModelStencil 0");
			} else {
				PushToConsole("SkelModelStencil 1");
			}
			chams = !chams;
			Sleep(100);
		}
     ...
}
First of all, let me say, nice post mate. Really concise, detailed and above all, logical.

Also, I was under the impression everyone wrote their hotkeys as you have done above, I didn't realise so many people used a hotkey just to toggle the boolean variable and then continually push the commands.

Also, with this:

Code:
void __cdecl PushToConsole( const char* szCmd )
{
	DWORD dwCShell = (DWORD)GetModuleHandleA("CShell.dll");
	if( dwCShell != NULL )
	...
Correct me if I'm wrong, I'm also a beginner in C++ but doesn't the "while(true)" in "void main()" come from the "IsGameReadyForHook" boolean? that procedure already checks whether the ModuleHandle of Cshell is NULL and returns true/false accordingly.

Again, I really liked the post, good work!
Quote Originally Posted by Jason View Post


First of all, let me say, nice post mate. Really concise, detailed and above all, logical.

Also, I was under the impression everyone wrote their hotkeys as you have done above, I didn't realise so many people used a hotkey just to toggle the boolean variable and then continually push the commands.

Also, with this:

Code:
void __cdecl PushToConsole( const char* szCmd )
{
	DWORD dwCShell = (DWORD)GetModuleHandleA("CShell.dll");
	if( dwCShell != NULL )
	...
Correct me if I'm wrong, I'm also a beginner in C++ but doesn't the "while(true)" in "void main()" come from the "IsGameReadyForHook" boolean? that procedure already checks whether the ModuleHandle of Cshell is NULL and returns true/false accordingly.

Again, I really liked the post, good work!
Um no.. The while(true) is just a way of writing an infinate loop. You could also write it like:
while(1)
for( ; ; )
It doesn't really matter, it is just a loop that never ends (until you end the program). The IsGameReadyForHook method checks if all the modules are loaded and returns true when they are. Then in dwHackThread or whatever you call yours it only calls the main thread once IsGameReadyForHook returns true, so maybe thats what your thinking of. And the reason that is in the PushToConsole method is because it is a way of making that method undetected.
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us