| View previous topic :: View next topic |
| Author |
Message |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sun Mar 02, 2008 11:06 am Post subject: [C++] Console Trainer |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Mar 02, 2008 11:22 am Post subject: |
|
|
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 |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sun Mar 02, 2008 11:49 am Post subject: |
|
|
Thank you!
But why can't I use a command with a space in it?
|
|
| Back to top |
|
 |
systat Advanced Cheater
Reputation: 0
Joined: 15 Feb 2008 Posts: 54
|
Posted: Sun Mar 02, 2008 11:54 am Post subject: |
|
|
use
| Code: | | cin.getline(Command,MAX_PATH); |
_________________
uuuuuuuuuuuuu |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Mar 02, 2008 11:56 am Post subject: |
|
|
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 |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sun Mar 02, 2008 12:22 pm Post subject: |
|
|
That's kinda amazing.
With this way I don't even have to explode the string.
Thanks again
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun Mar 02, 2008 1:31 pm Post subject: |
|
|
If your problem was that space thingy, use std::getline.
std::getline(std::cin, gcommand);
-> No need for windows.h ;)
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Mar 02, 2008 2:15 pm Post subject: |
|
|
| Jani wrote: | If your problem was that space thingy, use std::getline.
std::getline(std::cin, gcommand);
-> No need for windows.h  |
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 |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Mar 03, 2008 2:12 am Post subject: |
|
|
| 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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Mar 03, 2008 8:17 am Post subject: |
|
|
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 |
|
 |
|