CLEO Help Loosing my sanity...

CLEO related
Status
Not open for further replies.

JaggerJam

Active member
Joined
Sep 14, 2017
Messages
97
Reaction score
21
So, idk why but I have a weird bug, or I'm blind+dumb... My problem consist in a fucking variable which SOMEHOW re-writes it self from nothing when I'm using say keyword to execute a command. Here is a screenshot with this:

The variable 1@ contains the message from 27@ by using %n where contains the pointer to its' position within the text "offset of %n within the text + pointer to text begining = pointer to %n (the begining of 2nd parrameter" and in 0@ contains the ID.
Java:
{$CLEO}
{$INCLUDE SF}
0000:

repeat
wait 0
until SAMP.Available()
0b34: "fmm" @reat

0BE1: raknet setup_outcoming_rpc_hook @out_phone
alloc 29@ 256

while true
wait 0

end

:reat
0A92: create_custom_thread "sms_test.cs"
0A93: end_custom_thread
SAMP.CmdRet()

:out_phone
0BE5: raknet 31@ = get_hook_param PARAM_PACKETID
if 31@ == RPC_SERVERCOMMAND
then 
    0C11: memset destination 29@ value 0 size 256
  
    0BE5: raknet 31@ = get_hook_param PARAM_BITSTREAM
    0BE7: raknet 30@ = bit_stream_read 31@ type BS_TYPE_INT
    0BE8: raknet bit_stream 31@ read_array 29@ size 30@
    0C1E: array 29@ element 30@ el_size 1 = 0
  
    if 0C29: -1 = stristr string1 29@ string2 "/sms"
    then
        alloc 0@ 64
        0AC7: 1@ = var 1@ offset
        0AA5: call 0x8220AD num_params 4 pop 4 1@ 0@ "/sms %s %n" 29@
        005a: 1@ += 29@
        0C17: 2@ = strlen 1@
        0C1E: array 1@ element 2@ el_size 1 = 0
        chatmsg "ID: %s | Message: %s" -1 0@ 1@
        say "/number %s" 0@
        chatmsg "ID: %s | Message: %s" -1 0@ 1@
        free 0@
        0BE0: raknet hook_ret false
    end
  
end
0BE0: raknet hook_ret true

So what is really happening is after say my 1@ is getting the last 2 digits from 0@ and formats it's self....... So I've tried every method possible (using 0ab1:; calculate manually position of the text, separate it from RPC in while loop, E.V.E.R.Y.T.H.I.N.G., using 0AD4:....)

Someone please help, I can't no more.... fuck CLEO
 

Attachments

  • 1606430144189.png
    1606430144189.png
    76.5 KB · Views: 9

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
149
The problem is that you're treating pointer as if it was a value. When %n is encountered in "sscanf" it expects a pointer, which you supplied (using 0AC7 : 1@), then sscanf overwrites value at provided address, instead of reading that value (and adding 29@ to it) you're adding 29@ to the pointer. You should read value at 1@ first, and then add 29@ to it
 
Last edited:

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
What do you mean about read value?

Here is your topic about text handlig: http://ugbase.eu/index.php?threads/tutorial-text-handling.19741/
I've done like u said there.

Here is what @monday is talking about, try playing with this code and read the comments:
Code:
/*
USAGE:
/testing /sms <single word> <sentence>
/testing /sms 17 hello jaggerjam and monday
/testing /sms monday greetings from ajom, are you with jaggerjam?
*/

{$CLEO}
0000:
repeat
    wait 0
until SAMP.Available()

0B34: samp register_client_command "testing" to_label @activation

0BDE: pause_thread 0 // main while loop is not needed on this script

:activation
    0B35: samp 0@ = get_last_command_params // for simulation purposes, returns the pointer to string "/sms <single word> <sentence>"

// ------- do your sscanf like this
    alloc 1@ 64 // I am guessing this can be either a player id or a player name that is why you wat to treat ID as a string...
    0AA5: call 0x8220AD num_params 4 pop 4 2@v 1@ "/sms %s %n" 0@ // all parameters of 0x8220AD needs to be a pointer , 0@ holds the pointer of the message
    // now 2@ has an integer value which is the offset of the remaining string , respect to 0@
    005A: 2@ += 0@ // got the pointer of the remaining string
    chatmsg "ID:%s , Message=%s" -1 1@ 2@
    free 1@
// -------
samp.CmdRet()
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
149
I was wrong, my bad. It looks like the problem is about passing pointer to itself.

C:
#include <stdio.h>

int main()
{
    const char *s = "abc%n";
    char parsed[100] = {0};
  
  
    // this works
    int a;
    sscanf(s, "abc%n", &a);
    printf("%d\n",a);
  
      
    // this doesn't (causes segmentation fault):
    int b;
    b = &b;
    sscanf(s, "abc%n", b);
    printf("%d\n", b);

    return 0;
}

I have no idea why is it like this
 
Last edited:
Status
Not open for further replies.
Top