CLEO Help Help with cleo

CLEO related
Status
Not open for further replies.

Edvincik

Well-known member
Joined
Mar 15, 2016
Messages
399
Reaction score
26
Hello guys, how to make cleo that auto press "Taip" button. You can see what i am talking about in this video.
https://youtu.be/2DkPk_KQL64
Thanks for help.
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
Wtf are you ignoring my message?

supahdupahnubah said:
To make a dialog key press you can use : 0B47: samp close_current_dialog_with_button 0@, 0 goes for right button, 1 for left, so you use it like this : 0B47: 1

OFC it is requires sampfuncs SB data and ingame plugin
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
springfield said:
Pressing enter should work too, since it will close the dialog with button 0(left).

Ok close work. How detect if is "Taip" ?

Something like that:
Now "Taip" are in the right, then close the must go to dialog with button 1(right).
Else
Now "Taip" are in the left, then close the must go to dialog with button 0(left).
So how detect if "Taip" are right or left ?
@springfield
@supahdupahnubah
 

Edvincik

Well-known member
Joined
Mar 15, 2016
Messages
399
Reaction score
26
Parazitas said:
springfield said:
Pressing enter should work too, since it will close the dialog with button 0(left).

Ok close work. How detect if is "Taip" ?

Something like that:
Now "Taip" are in the right, then close the must go to dialog with button 1(right).
Else
Now "Taip" are in the left, then close the must go to dialog with button 0(left).
So how detect if "Taip" are right or left ?
@springfield
@supahdupahnubah
@monday
Because in our case buttons all the time are random, like one time its right and the other time its left
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
There's lot of excuses if someone\you want to use this snippet globaly (i.e. on other server), so you have to adapt it for global usage yourself
Also I could've use Dialog ID check, but used Title one, in case admin on your server will change its ID and also Title, so you will only have to update title and string allocation size
However it was kinda hard for me, because of high body temperature, but I did it because it was quite interesting
In exchange for that, I only want you to make something simillar, so I will know you're not just a freebie, but also capable to do something yourself
Also @springfield am I retarded or there's no actual way to read string from memory properly, so I have to do this noobish function myself?  :-/ :-/

P.S. Don't judge me for lot of "so" in this text, ty

[shcode=cpp]
{$CLEO .cs}

if not 31@ = samp.Base()
then
end_thread
else
    while not samp.Available()
    wait 100
    end
end

0000:
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect


//get pointer to dialog class
0AF7: samp 13@ = get_base
13@ += 0x21A0B8
0A8D: 13@ = 13@ 4 0
13@ += 0x20
0A8D: 13@ = 13@ 4 0

while true
wait 0

if 
0B4C: samp is_dialog_active -1 //is any dialog active
then
    alloc 3@ 256 //alloc memory for string                              
    0BD8: samp get_dialog_caption 3@ //get title of dialog
    if 0C14: strcmp string1 2@ string2 3@ //comparing 
    then
        0AB1: call_scm_func @allahu_akbar 2 button_to_detect 0@ initialized_ptr 13@ //calling function on line ¹43
    end
end
wait 500 // avoid function flooding in both cases (succ\fail), just wooden pc things

end

:allahu_akbar
//so on this function call 0@ from line ¹36 equals 0@, while 13@ equals 1@
1@ += 0x1AD //left button string offset, right button offset is 0x1315
0C17: 2@ = strlen 0@ //size of string to detect (needed to read right amount of bytes for string) 
alloc 3@ 128 //alloc memory for button string
0AB1: call_scm_func @_read_string 2 address 1@ size 2@ output 3@ //call function on line ¹60
if 0C14: strcmp string1 0@ string2 3@ //comparing 
    then //if on left
        0B47: samp close_current_dialog_with_button 1
        ret 0
    else //else if on right
        0B47: samp close_current_dialog_with_button 0
        ret 0
    end
chatmsg "Something is happened inside of my function, damn" 120007 
ret 0

:_read_string //Usage : 0AB1: call_scm_func @_read_string 2 address 0@ size 1@ output 2@
0085: 2@ = 1@ * 2 // (int)
alloc 3@ 2@
format 3@ ""
for 5@ = 1 to 1@
0A8D: 4@ = 0@ 1 0
format 3@ "%s%c" 3@ 4@
0@ += 1
end
ret 1 3@
[/shcode]
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
supahdupahnubah said:
There's lot of excuses if someone\you want to use this snippet globaly (i.e. on other server), so you have to adapt it for global usage yourself
Also I could've use Dialog ID check, but used Title one, in case admin on your server will change its ID and also Title, so you will only have to update title and string allocation size
However it was kinda hard for me, because of high body temperature, but I did it because it was quite interesting
In exchange for that, I only want you to make something simillar, so I will know you're not just a freebie, but also capable to do something yourself
Also @springfield am I retarded or there's no actual way to read string from memory properly, so I have to do this noobish function myself?  :-/ :-/

P.S. Don't judge me for lot of "so" in this text, ty

[shcode=cpp]
{$CLEO .cs}

if not 31@ = samp.Base()
then
end_thread
else
    while not samp.Available()
    wait 100
    end
end

0000:
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect


//get pointer to dialog class
0AF7: samp 13@ = get_base
13@ += 0x21A0B8
0A8D: 13@ = 13@ 4 0
13@ += 0x20
0A8D: 13@ = 13@ 4 0

while true
wait 0

if 
0B4C: samp is_dialog_active -1 //is any dialog active
then
    alloc 3@ 256 //alloc memory for string                              
    0BD8: samp get_dialog_caption 3@ //get title of dialog
    if 0C14: strcmp string1 2@ string2 3@ //comparing 
    then
        0AB1: call_scm_func @allahu_akbar 2 button_to_detect 0@ initialized_ptr 13@ //calling function on line ¹43
    end
end
wait 500 // avoid function flooding in both cases (succ\fail), just wooden pc things

end

:allahu_akbar
//so on this function call 0@ from line ¹36 equals 0@, while 13@ equals 1@
1@ += 0x1AD //left button string offset, right button offset is 0x1315
0C17: 2@ = strlen 0@ //size of string to detect (needed to read right amount of bytes for string) 
alloc 3@ 128 //alloc memory for button string
0AB1: call_scm_func @_read_string 2 address 1@ size 2@ output 3@ //call function on line ¹60
if 0C14: strcmp string1 0@ string2 3@ //comparing 
    then //if on left
        0B47: samp close_current_dialog_with_button 1
        ret 0
    else //else if on right
        0B47: samp close_current_dialog_with_button 0
        ret 0
    end
chatmsg "Something is happened inside of my function, damn" 120007 
ret 0

:_read_string //Usage : 0AB1: call_scm_func @_read_string 2 address 0@ size 1@ output 2@
0085: 2@ = 1@ * 2 // (int)
alloc 3@ 2@
format 3@ ""
for 5@ = 1 to 1@
   0A8D: 4@ = 0@ 1 0
   format 3@ "%s%c" 3@ 4@
   0@ += 1
end
ret 1 3@
[/shcode]

Thank you very much, i love this mod.
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
supahdupahnubah said:
Also @springfield am I retarded or there's no actual way to read string from memory properly, so I have to do this noobish function myself?  :-/ :-/

1@ += 0x1AD //left button string offset, right button offset is 0x1315

Normally strings are null terminated, so they end with a 0 in memory -> "0x55, 0x66 ... 0x00". That's how most C string function understand where a string ends. 

So, if a variable holds the address of the text start then you can use most functions like strlen, strcpy, strncpy on it, without having to worry it will read behind the end of the text.

So a shorter version would be 

[shcode=cpp]

if 0B4C:  samp is_dialog_active -1
then
    //check if caption contains 'AFK'

    0BB0: samp 0@ = get_dialog_info_ptr
    0@ += 0x20
    0A8D: 0@ = 0@ 4 0
    0@ += 0x1AD
            
    if 0C21: stricmp str1 0@ str1 "Taip"
    then 0B47: samp close_current_dialog_with_button 0
    else 0B47: samp close_current_dialog_with_button 1
    end           
end
[/shcode]
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
springfield said:
Normally strings are null terminated, so they end with a 0 in memory -> "0x55, 0x66 ... 0x00". That's how most C string function understand where a string ends. 

So, if a variable holds the address of the text start then you can use most functions like strlen, strcpy, strncpy on it, without having to worry it will read behind the end of the text.

So a shorter version would be 

Never thought about it, thanks!
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
Simplified, so it wont look that dumb, thanks to springfield <3

[shcode=cpp]
{$CLEO .cs}
0000:
while not samp.Available()
wait 100
end
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect
0BB0: samp 13@ = get_dialog_info_ptr
13@ += 0x20
0A8D: 13@ = 13@ 4 0
13@ += 0x1AD

while true
wait 0
if
0B4C: samp is_dialog_active -1
then
alloc 3@ 256
0BD8: samp get_dialog_caption 3@
if 0C14: strcmp string1 2@ string2 3@ //comparing
then
free 3@
if 0C14: strcmp string1 13@ string2 0@
then
0B47: samp close_current_dialog_with_button 1
else
0B47: samp close_current_dialog_with_button 0
end
end
end
wait 500
end
[/shcode]
 

Edvincik

Well-known member
Joined
Mar 15, 2016
Messages
399
Reaction score
26
supahdupahnubah said:
Simplified, so it wont look that dumb, thanks to springfield <3

[shcode=cpp]
{$CLEO .cs}
0000:
while not samp.Available()
   wait 100
end
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect
0BB0: samp 13@ = get_dialog_info_ptr
13@ += 0x20
0A8D: 13@ = 13@ 4 0
13@ += 0x1AD

while true
wait 0
if
0B4C: samp is_dialog_active -1
then
   alloc 3@ 256                          
   0BD8: samp get_dialog_caption 3@
   if 0C14: strcmp string1 2@ string2 3@ //comparing
   then
       free 3@
       if 0C14: strcmp string1 13@ string2 0@
       then
           0B47: samp close_current_dialog_with_button 1
       else
           0B47: samp close_current_dialog_with_button 0
       end
   end
end
wait 500
end
[/shcode]
Damn,gods of cleo :D
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
And to lose 3 more lines(cuz y not), if the text is smaller than or equal to 7 chars we can use 

0@s = 'Taip'
2@s = 'AFK'

without allocating memory, also.. free 3@ should be in the same context as alloc 3@

alloc 3@
    if condition
    then do_stuff
    end
free 3@

Nice stuff, someone should post a snippet to get/read the dialog buttons since there's no default opcode for this, i think.
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
springfield said:
also.. free 3@ should be in the same context as alloc 3@

Why? I thought you can easily free it when it's not needed anymore, i.e. inside condition

springfield said:
Nice stuff, someone should post a snippet to get/read the dialog buttons since there's no default opcode for this, i think.

I'd make it but afraid there might be even better version of this with RPC and other stuff which I didn't get used to
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
supahdupahnubah said:
Why? I thought you can easily free it when it's not needed anymore, i.e. inside condition

3@ contains a pointer to the allocated memory, if the strcmp compare fails(dialog caption is not 'AFK') new memory will be allocated on the same variable, and the previous pointer will be lost, thus the previous allocated memory won't be freed.

supahdupahnubah said:
I'd make it but afraid there might be even better version of this with RPC and other stuff which I didn't get used to

This one wouldn't use SAMPFUNCS, since you'd be reading from memory.
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
springfield said:
3@ contains a pointer to the allocated memory, if the strcmp compare fails(dialog caption is not 'AFK') new memory will be allocated on the same variable, and the previous pointer will be lost, thus the previous allocated memory won't be freed.

Ow shiettt how couldn't I notice this sequence error before, lol, was dumb, thanks
 
Status
Not open for further replies.
Top