[Release] Async task in c++

12/13/2014 00:38 Caesarw#1
Alright, here comes a little trick you guys can use to write a pake script.
What I gonna introduce is the async function template comes with c++11.

So, simple sample. Suppose you wanna constantly use one skill, in your SendHook function:
Code:
...
int opcode=packet.GetOP();
switch (opcode) {
case 0x6987: int skillID=packet.GetElement(0)->int32;
             if (skillID==AUTO_SKILL) {
               std::async([]() { Sleep(5000); use_skill(AUTO_SKILL); });
             }
             break;
...
}
...
Note a lambda is passed to async call. What is does is basically send 0x6982 to use the same skill 5 seconds after every time the skill was released, assuming the CD is 5 seconds. You can manually adjust the time to wait.

The sample above is the most basic thing async can do. However it's very powerful for writing automated stuff, figure it out.
12/13/2014 11:26 DarkOPM#2
#moved
12/15/2014 09:16 Ayamin#3
Oooo is that similar to an anonymous function?
12/15/2014 16:22 Caesarw#4
Quote:
Originally Posted by Ayamin View Post
Oooo is that similar to an anonymous function?
yep :D
the interesting feature of c++ lambda is capture
which can access variables outside the lambda function
12/16/2014 12:04 ayjani#5
it looks like c++ has got some sugar, hopefully they solved their garbage collector problems.

and btw,
doing sleep inside async thread is generally bad practice
the whole purpose of async programming is to get rid of things like sleep and poll
if you want a pace limit, build a queue and pace it properly.
01/28/2015 01:44 Terrorpur#6
what about keypresser or u need a specific tool >??
02/12/2015 21:21 anonentity#7
Quote:
Originally Posted by Caesarw View Post
Alright, here comes a little trick you guys can use to write a pake script.
What I gonna introduce is the async function template comes with c++11.

So, simple sample. Suppose you wanna constantly use one skill, in your SendHook function:
Code:
...
int opcode=packet.GetOP();
switch (opcode) {
case 0x6987: int skillID=packet.GetElement(0)->int32;
             if (skillID==AUTO_SKILL) {
               std::async([]() { Sleep(5000); use_skill(AUTO_SKILL); });
             }
             break;
...
}
...
Note a lambda is passed to async call. What is does is basically send 0x6982 to use the same skill 5 seconds after every time the skill was released, assuming the CD is 5 seconds. You can manually adjust the time to wait.

The sample above is the most basic thing async can do. However it's very powerful for writing automated stuff, figure it out.
Could you please tell me how did you manage to call the Send function in the async lambda function? I have tried similar methods but the client crashes every time it reaches the Send function.
Thanks.
02/13/2015 16:52 Caesarw#8
Quote:
Originally Posted by anonentity View Post
Could you please tell me how did you manage to call the Send function in the async lambda function? I have tried similar methods but the client crashes every time it reaches the Send function.
Thanks.
you are right.
all code in aysnc block run in a newly created thread.
so..
put all aysnc tasks outside the client process, then use message to communicate with alissa's window, which will then call send in the main thread.:D