| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Mon Jul 27, 2009 12:04 am Post subject: [C++] Loops/counter..concept help |
|
|
Basically I have 3 phrases that I want to send to my game.
And One button that I want to press every 10 minutes or so.
| Code: | //NOTE - THIS IS PSEUDO-CODE
SendText("Phrase1");
SendText("Phrase2");
SendText("Phrase3");
PressButton(J); |
However, I don't know enough about sending packets so I'm just manually inputting these phrases. The problem with this is that the letter J ends up being typed into one of my phrases rather than being pressed as a button.
So I came up with this idea:
Every time I send a phrase, increase an integer by one. When the integer gets to a certain number, have it press J and reset the counter (integer). Then start the process all over again.
Unfortunately, I am having trouble forming this in code. What exactly am I looking at here? An if statement within an if statement?
Any ideas or snippets would be greatly appreciated.
-manc
_________________
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Mon Jul 27, 2009 2:28 am Post subject: |
|
|
I'm not sure what you're looking for..explain more?
| Code: |
void SendPhrases()
{
while(TRUE)
{
while(count < 6000)
{
SendText("Phrase1");
SendText("Phrase2");
SendText("Phrase3");
counter++;
Sleep(10);
}
if(PressButton(J))
counter = 0;
}
}
|
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Mon Jul 27, 2009 9:41 am Post subject: |
|
|
Ok..I'm trying to make an autochat / autofeeder for a pet in ... well...you know what game I'm talking about MS?
Thats just the best method I could think of . Alternatives are welcome.
I dont want my pet to go hungry .
Let me see if I can make a rough sketch.
| Code: | loop:
for (int i = 0; i < 100; i++)
{
SendText ("Phrase1");
SendText ("Phrase2");
SendText ("Phrase3");
}
PressButton(J);
goto loop; |
I've always heard that goto should only be used as a last resort though.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Jul 27, 2009 10:33 am Post subject: |
|
|
| Code: | for(;;) {
for (int i = 0; i < 100; i++)
{
SendText ("Phrase1");
SendText ("Phrase2");
SendText ("Phrase3");
}
PressButton(J);
} | ? :P
If you want the button J pressed every 10th minute, use timers...
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Mon Jul 27, 2009 11:15 am Post subject: |
|
|
That's almost exactly what i did lol
and it basically only does it every 10 minutes.
Anyway, if you're talking about MS..just take the return of the send func that is used to send the feed packet and trace to the top to find the feed api.
Then hook it, find the parameters, and call it yourself instead of pressing a button.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jul 27, 2009 12:50 pm Post subject: |
|
|
| Jani wrote: | | Code: | for(;;) {
for (int i = 0; i < 100; i++)
{
SendText ("Phrase1");
SendText ("Phrase2");
SendText ("Phrase3");
}
PressButton(J);
} | ?
If you want the button J pressed every 10th minute, use timers... |
Wouldn't it be better to have 2 threads? 1 sending the 3 phrases with 1000MS sleep between each phrase, and 1 with a 600000 MS sleep between the pressing of J?
If he uses timers, it relies on the messaging system and could miss pressing J (in my experience using timers for bots on the same thread)
_________________
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Mon Jul 27, 2009 1:03 pm Post subject: |
|
|
| blankrider wrote: | | Jani wrote: | | Code: | for(;;) {
for (int i = 0; i < 100; i++)
{
SendText ("Phrase1");
SendText ("Phrase2");
SendText ("Phrase3");
}
PressButton(J);
} | ?
If you want the button J pressed every 10th minute, use timers... |
Wouldn't it be better to have 2 threads? 1 sending the 3 phrases with 1000MS sleep between each phrase, and 1 with a 600000 MS sleep between the pressing of J?
If he uses timers, it relies on the messaging system and could miss pressing J (in my experience using timers for bots on the same thread) |
Then what if it presses J while typing a phrase ?
You'd have to do your own little thread separation thing, like don't send the button if you're in the middle of typing the phrase lol.
Anyway, 2 threads is harder than 1 if you just do it my way or Jani's.
(I wouldn't use timers..)
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jul 27, 2009 2:23 pm Post subject: |
|
|
| smartz993 wrote: | | blankrider wrote: | | Jani wrote: | | Code: | for(;;) {
for (int i = 0; i < 100; i++)
{
SendText ("Phrase1");
SendText ("Phrase2");
SendText ("Phrase3");
}
PressButton(J);
} | ?
If you want the button J pressed every 10th minute, use timers... |
Wouldn't it be better to have 2 threads? 1 sending the 3 phrases with 1000MS sleep between each phrase, and 1 with a 600000 MS sleep between the pressing of J?
If he uses timers, it relies on the messaging system and could miss pressing J (in my experience using timers for bots on the same thread) |
Then what if it presses J while typing a phrase ?
You'd have to do your own little thread separation thing, like don't send the button if you're in the middle of typing the phrase lol.
Anyway, 2 threads is harder than 1 if you just do it my way or Jani's.
(I wouldn't use timers..) |
yea, i would do it your way with 1 second sleep in between each and a count of 200
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Jul 28, 2009 5:38 am Post subject: |
|
|
| smartz993 wrote: | | That's almost exactly what i did lol | Just telling the guy how to get rid of the goto.
| blankrider wrote: | | Wouldn't it be better to have 2 threads? | If I were serious about doing this, I'd use events NOT threads... Having a thread for every thing you do is just bad programming. Consider you had 100 things to do when it's their time to act.. 100 threads, eh? But again, I'm not sure what the guy wants. I just saw the goto and decided to reply how to get rid of it.
Qt timer example:
| Code: | QTimer *t1 = new QTimer( this );
connect( t1, SIGNAL( timeout() ), this, SLOT( pressTheJButton() ) );
QTimer *t2 = new QTimer( this );
connect( t2, SIGNAL( timeout() ), this, SLOT( sendPhrase() ) );
/* pressTheJButton() slot will be called every 10th minute.
* sendPhrase() slot will be called every 5th second.
*/
t1->start( 10*60*1000 );
t2->start( 5*1000 ); |
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Jul 28, 2009 6:16 am Post subject: |
|
|
| Jani wrote: | | smartz993 wrote: | | That's almost exactly what i did lol | Just telling the guy how to get rid of the goto.
| blankrider wrote: | | Wouldn't it be better to have 2 threads? | If I were serious about doing this, I'd use events NOT threads... Having a thread for every thing you do is just bad programming. Consider you had 100 things to do when it's their time to act.. 100 threads, eh? But again, I'm not sure what the guy wants. I just saw the goto and decided to reply how to get rid of it.
Qt timer example:
| Code: | QTimer *t1 = new QTimer( this );
connect( t1, SIGNAL( timeout() ), this, SLOT( pressTheJButton() ) );
QTimer *t2 = new QTimer( this );
connect( t2, SIGNAL( timeout() ), this, SLOT( sendPhrase() ) );
/* pressTheJButton() slot will be called every 10th minute.
* sendPhrase() slot will be called every 5th second.
*/
t1->start( 10*60*1000 );
t2->start( 5*1000 ); |
|
The reason i said use a sep thread instead of a timer is something irwin told me when i made a bot that used timers, and alot of people that tested it. The timer can easily be ignored because of the other timer hogging the messaging que and it will miss it's action. It is bad to use seperate threads in almost all other applications, but if you have to guarentee that the button is pressed, a seperate thread does that.
Using your code, the J button will certainly be skipped some, and with a large interval like 10 minutes, you can't afford to miss the action.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Jul 28, 2009 9:24 am Post subject: |
|
|
| blankrider wrote: | | The timer can easily be ignored because of the other timer hogging the messaging que and it will miss it's action. | A timer won't miss it's action. Well, maybe a badly designed one could, but not for example QTimer. The only case the timer would miss it's action is when the OS timer precision was lower than the interval you wanted. That would be a very short time interval, so if the interval is seconds, it won't cause any problems.
If a timer could miss it's action (constantly), what's the point of implementing timers?
| blankrider wrote: | | Using your code, the J button will certainly be skipped some | It won't try it. Leave the app running for let's say years and all the timers will be there as long as your system doesn't crash.
Also, it's the other process' fault if it doesn't process the J button if it was send to the process. If you wanted to make my code perfect, you'd make sure that the other timer doesn't send it's input to the process (ie. stop the timer) and then send the J button.. I found it to be trivial, because the topic went a little off and we were talking about timers.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Jul 28, 2009 10:39 am Post subject: |
|
|
| Jani wrote: | | blankrider wrote: | | The timer can easily be ignored because of the other timer hogging the messaging que and it will miss it's action. | A timer won't miss it's action. Well, maybe a badly designed one could, but not for example QTimer. The only case the timer would miss it's action is when the OS timer precision was lower than the interval you wanted. That would be a very short time interval, so if the interval is seconds, it won't cause any problems.
If a timer could miss it's action (constantly), what's the point of implementing timers?
| blankrider wrote: | | Using your code, the J button will certainly be skipped some | It won't try it. Leave the app running for let's say years and all the timers will be there as long as your system doesn't crash.
Also, it's the other process' fault if it doesn't process the J button if it was send to the process. If you wanted to make my code perfect, you'd make sure that the other timer doesn't send it's input to the process (ie. stop the timer) and then send the J button.. I found it to be trivial, because the topic went a little off and we were talking about timers. |
I used windows timers. Is QTimer really that much better? I've never heard of it. I KNOW windows timers skips sometimes
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Jul 28, 2009 12:39 pm Post subject: |
|
|
| blankrider wrote: | | I used windows timers. Is QTimer really that much better? I've never heard of it. I KNOW windows timers skips sometimes | Well.. I haven't ever used Windows timers, so Iono about them. I doubt it that they would skip actions if you use them "normally." It might not be very precise, but it should fire when it's meant to be fired. Of course you could code some nice little app showing it skipping :)
QTimer is part of Qt..
Anyway, here's a nice little app testing QTimer. If you manage to get red text, I admit I was wrong, else timers work perfectly.
FAQ:
Q: What does it do?
A: Starts a 1000ms timer and records the start time. Waits for user to stop and then compares the timer results and real seconds elapsed. If they match, you get a green text, otherwise red.
Q: I have 1 s and 957 ms and the timer has only hit once. Why I get green text?
A: The program compares full seconds. Because 2000ms > 1957ms, you get green text. So, basically, you need full seconds to have the timer increase it's counter. With 2 s and 0 ms the counter should be at 2 and you should get green text again.
Q: I cannot run the program?
A: Download the dlls.zip attached to this post and extract to the very same folder with the .exe.
Q: I still cannot run the program?
A: Download and install this (if you're unsure which one, try x86):
x86: http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en
x64: http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en
Q: Was this one tested at all?
A: Nope, tell me if you find any bugs, or can't run it. :) I'll fix 'em as soon as possible!
Q: Where to download?! Gimme the links already!
A: Ok ok, chill! Here we go:
Root: http://jani.bplaced.net/QTimerTest/
QTimerTest: http://jani.bplaced.net/QTimerTest/QTimerTest.zip
dlls: http://jani.bplaced.net/QTimerTest/dlls.zip
EDIT: you could also compete for the fastest double click.. No cheating allowed! I keep getting 125ms.
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Jul 28, 2009 3:08 pm Post subject: |
|
|
Jani, I don't know if you played the game I was talking about, but I don't think blankrider was literally talking about it skipping or not pressing the button. Rather, he meant it might be pressed at the wrong time, which in the eyes of the game would mean it didnt get pressed (it would be inputted as text like you would be talking in the game, rather than as a hotkey/command).
Also wanted to say thanks for all the help to everyone.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed Jul 29, 2009 5:16 am Post subject: |
|
|
| manc wrote: | | Rather, he meant it might be pressed at the wrong time, which in the eyes of the game would mean it didnt get pressed (it would be inputted as text like you would be talking in the game, rather than as a hotkey/command). | If that's the case, using threads will just make it more complicated, because you'd need to sync the threads somehow. Syncing two timers is way more easier than syncing threads. As I said, it's trivial to implement in demonstration of timers.
|
|
| Back to top |
|
 |
|