Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Console Trainer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sun Mar 02, 2008 11:06 am    Post subject: [C++] Console Trainer Reply with quote

Hey,

I want to make a trainer. Just for a something like minesweeper in a console.
But I wanna make it with commands.
Like "/freezeTime on" and "/freezeTime off".
But I don't know how to save it the writen command in a string.

So, wanna save a command typed by a user in a STRING that I can easly explode it and check for every parameter of the command with if.
And then do what the command certain command is supposed to do.

I already tried using this:
Code:
int GetCommands(){
   cin >> gcommand;

   cout << gcommand << "  <-- just a test" << "\n";
   if (gcommand == "lol"){
      cout << "Not funny!";
      cin.get();
      cin.ignore();
   }
   else
   {
      cout << "You said: " << gcommand;
      cin.get();
      cin.ignore();
   }

   return 0;
}

("gcommand" is a global variable = string)

But this does not work :/

thanks in advance.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 02, 2008 11:22 am    Post subject: Reply with quote

use the _tcscmp function to compare strings

Code:
#include <tchar.h>
#include <windows.h>
#include <iostream>

TCHAR Command[MAX_PATH];
LPCWSTR lpCommand1 = L"/talk";

int main( int argc, char* argv )
{
   wprintf( L"Enter a command\n" );
   wscanf( L"%s", &Command );
   
   if ( _tcscmp( Command, lpCommand1 ) == 0 )
   {
      wprintf( L"Hi" );
   }
   
   std::cin.sync();
   std::cin.ignore();
   return 0;
}

_________________
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sun Mar 02, 2008 11:49 am    Post subject: Reply with quote

Thank you!
But why can't I use a command with a space in it?
Back to top
View user's profile Send private message
systat
Advanced Cheater
Reputation: 0

Joined: 15 Feb 2008
Posts: 54

PostPosted: Sun Mar 02, 2008 11:54 am    Post subject: Reply with quote

use

Code:
cin.getline(Command,MAX_PATH);

_________________
uuuuuuuuuuuuu
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 02, 2008 11:56 am    Post subject: Reply with quote

You can do this if you want a space:

Code:
#include <tchar.h>
#include <windows.h>
#include <iostream>

TCHAR Command[MAX_PATH];
TCHAR End[MAX_PATH];
LPCWSTR lpCommand1 = L"/talk";
LPCWSTR lpEnd      = L"on";

int main( int argc, char* argv )
{
   wprintf( L"Enter a command\n" );
   wscanf( L"%s %s", &Command, &End );

   if ( _tcscmp( Command, lpCommand1 ) == 0 )
   {
      if ( _tcscmp( End, lpEnd ) == 0 )
      {
         wprintf( L"Hi" );
      }
   }

   std::cin.sync();
   std::cin.ignore();
   return 0;
}

_________________
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sun Mar 02, 2008 12:22 pm    Post subject: Reply with quote

That's kinda amazing.
With this way I don't even have to explode the string.

Thanks again Smile
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Mar 02, 2008 1:31 pm    Post subject: Reply with quote

If your problem was that space thingy, use std::getline.

std::getline(std::cin, gcommand);

-> No need for windows.h ;)
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 02, 2008 2:15 pm    Post subject: Reply with quote

Jani wrote:
If your problem was that space thingy, use std::getline.

std::getline(std::cin, gcommand);

-> No need for windows.h Wink


Hes making a Console Trainer

hes gonna need Windows.h no matter what he does.
and _tcscmp comes from tchar.h, along with everyother UNICODE function/definition.

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Mar 03, 2008 2:12 am    Post subject: Reply with quote

lurc wrote:
Hes making a Console Trainer

hes gonna need Windows.h no matter what he does.
For what? Could you give me an example. I do know a few cases, but do you.. ;)

Btw.. How do you think ppl code trainers for games running on *nix systems?

Oh yeh, and if you use std::string/std::wstring, you can do the comparison without strcmp. A == will be fine, just like you did in the first post.

And why to code in C++ if the only C++ function you're using is std::cin? And you're using it to pause your proggy.. :P
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Mar 03, 2008 8:17 am    Post subject: Reply with quote

Doesn't Linux use ptrace for reading/writing to memory..? If so that kinda defeats that argument as Windows uses something completely different so coding this for both platforms would have some different code in the first place let alone different headers for it's API.

WriteProcessMemory is defined in winbase.h, without including windows.h you will run into countless errors as you will be missing other important includes that are needed.

On Linux, ptrace is found in sys/ptrace.h, again different includes.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites