CLEO Help Read Chat getting extra text

CLEO related
Status
Not open for further replies.

Lukahlyo

Member
Joined
Nov 11, 2018
Messages
20
Reaction score
1
I'm using code from this thread: http://ugbase.eu/index.php?threads/cleo.21467/#post-125764
I've replaced it with what I need to get, but it's also catching color codes from SAMP. What might be going on?
WTpK9iR.png

Here's my edit:
Code:
{$CLEO .cs}

0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

WHILE TRUE
   WAIT 0

IF
0B61:  samp is_local_player_spawned
THEN
    FOR 10@ = 99 TO 99
        0AC8: 11@ = allocate_memory_size 260
        0AC8: 12@ = allocate_memory_size 260
        0B75: samp get_chat_string 10@ text_to 11@ prefix_to 12@ color_to 13@ prefix_color_to 14@
        IF
        0C29: 15@ = stristr string1 11@ string2 "Tienes un total de"
        THEN
            0C17: 16@ = strlen 15@
            IF
            0C29: 17@ = stristr string1 15@ string2 "Tienes un total de"
            THEN
                0C17: 18@ = strlen 17@
                0062: 16@ -= 18@
                0C24: strncpy destination 15@ source 15@ size 16@
                15@ += 19
                0AF9: samp say_msg "!!%s" 15@
                wait 3000
            END
        END
    END
END

END
 

Lukahlyo

Member
Joined
Nov 11, 2018
Messages
20
Reaction score
1
Thanks for these. I must be doing this horribly wrong, because merging it with the existing code always results in a crash. I've toyed around with it since you posted it and there's just no way I can possibly make this right.
Forgive the mess you may possibly see, but as far as my little understanding goes this *should* work?
Code:
{$CLEO .cs}

0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

WHILE TRUE
   WAIT 0 


IF
0B61:  samp is_local_player_spawned
THEN
    FOR 10@ = 99 TO 99 // GET TWO LAST LINES
        0AC8: 11@ = allocate_memory_size 260 // ALLOC TO GET TEXT
        0AC8: 12@ = allocate_memory_size 260 // ALLOC TO GET PREFIX - NOT USING , BUT IS IMPORTANT TO ALLOCATE
        0B75: samp get_chat_string 10@ text_to 11@ prefix_to 12@ color_to 13@ prefix_color_to 14@ // READ CHAT TEXT , ETC..
        IF
        0C29: 15@ = stristr string1 11@ string2 "Tienes un total de" // READ 1@ AND FIND PEACE OF TEXT, 5@ = RETURN ALL TEXT FROM THAT PEACE OF TEXT TILL END
        THEN
            0C17: 16@ = strlen 15@ // GET RETURNED TEXT SIZE
            IF
            0C29: 17@ = stristr string1 15@ string2 "Tienes un total de" // READ 5@ RETURNED TEXT AND FIND PEACE OF TEXT, 7@ = RETURN ALL TEXT FROM THAT PEACE OF TEXT TILL END
            THEN
                0C17: 18@ = strlen 17@ // GET RETURNED TEXT SIZE
                0062: 16@ -= 18@ // DELETE FROM 6@ SIZE, 8@ - RETURNED TEXT SIZE , NOW YOU KNOW THE SIZE OF TEXT WHICH YOU NEED DELETE FROM 5@ RETURNED STRING
                0C24: strncpy destination 15@ source 15@ size 16@ // COPY STRING WITH NEW SIZE OF TEXT, NOW YOU HAVE ONLY - /redeemcreds S610ppYKB5
                15@ += 19 // /redeemcreds = 12 CHARACTERS + ONE CHARACTER FOR SPACE, WHICH MEANS WE SKIP 13 CHARACTERS AND FINALLY TEXT IS - S610ppYKB5
                0AC8: 1@ = allocate_memory_size 1024
                0AB1: call_scm_func @changeString param_count 4 text 15@ FirstCharacter 123 SecondCharacter 125  memory_to_store_characters_as_text 1@
                wait 50
                0AF9: samp say_msg "!!%s" -1 1@ // Debug / logger or whatever we calling it... xD
                0A93: end_custom_thread
                wait 3000
            END // END - 0C29: 7@ = stristr string1 5@ string2 "to redeem"
        END // END - 0C29: 5@ = stristr string1 1@ string2 "/redeemcreds"
    END // END - FOR 0@ = 98 TO 99 // GET TWO LAST LINES
END // END - CHECK 0B61:  samp is_local_player_spawned
END // END - WHILE TRUE

:changeString
5@ = FALSE // inbracket
0C17: 31@ = strlen 15@
    for 30@ = 0 to 31@
        0085: 29@ = 15@ // copy pointer
        005A: 29@ += 30@  // add offset make loop
        0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
        if
        003B:   28@ == 1@  // (int)
        then
            5@ = TRUE // inbracket
        end
 
        if
        5@ == FALSE // inbracket
        THEN
            0A8C: write_memory 3@ size 1 value 28@ virtual_protect 1
            3@ += 1 // move to next address
        END
 
        if
        003B:   28@ == 2@  // (int)
        then
            5@ = FALSE // inbracket
        end
    end
0A8C: write_memory 3@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Fixed mistake which you made....
PHP:
{$CLEO .cs}

0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

WHILE TRUE
   WAIT 0
  
IF
0B61:  samp is_local_player_spawned
THEN
    0AC8: 11@ = allocate_memory_size 260
    0AC8: 12@ = allocate_memory_size 260
    0B75: samp get_chat_string 99 text_to 11@ prefix_to 12@ color_to 13@ prefix_color_to 14@
    0AC8: 15@ = allocate_memory_size 1024
    0AB1: @changeString 4 text 11@ FirstCharacter 123 SecondCharacter 125 memory_to_store_characters_as_text 15@
    IF
    0C29: $NOT_USED = stristr string1 15@ string2 "Tienes un total de"
    THEN
        0AC8: 16@ = allocate_memory_size 260
        0AB1: @get_digits_to_print 2 text 15@ memory_to_store_digits_as_text 16@
        0AF9: samp say_msg "!!%s" 16@
        wait 3000
    END
END

END

:changeString
5@ = FALSE // inbracket
0C17: 31@ = strlen 0@
for 30@ = 0 to 31@
    0085: 29@ = 15@ // copy pointer
    005A: 29@ += 30@  // add offset make loop
    0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
    if
    003B:   28@ == 1@  // (int)
    then
        5@ = TRUE // inbracket
    end

    if
    5@ == FALSE // inbracket
    then
        0A8C: write_memory 3@ size 1 value 28@ virtual_protect 1
        3@ += 1 // move to next address
    end

    if
    003B:   28@ == 2@  // (int)
    then
        5@ = FALSE // inbracket
    end
end
0A8C: write_memory 3@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0

:get_digits_to_print
{
    0@ = text
    1@ = pointer to memory where digits will be stored as text
}
0C17: 31@ = strlen 0@
for 30@ = 0 to 31@ 
    0085: 29@ = 0@ // copy pointer
    005A: 29@ += 30@  // add offset (as the loop progresses it becomes pointers to first-last character)
    0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
    if and
    28@ >= 0x30 // '0'
    28@ <= 0x39 // '9'
    then
        0A8C: write_memory 1@ size 1 value 28@ virtual_protect 1
        1@ += 1 // move to next address
    end
end
0A8C: write_memory 1@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
 
Last edited:

Lukahlyo

Member
Joined
Nov 11, 2018
Messages
20
Reaction score
1
Crash upon login.
I can kinda see the intent behind the correction, but isn't it trying to read from where there isn't anything stored?

EDIT: I'm throwing shit at the wall, seeing what sticks. I've changed a few things and I'm only managing to make it crash as soon as the game boots, then as soon as the login prompt pops up. I believe this spaghetti code is doomed.
 
Last edited:

Lukahlyo

Member
Joined
Nov 11, 2018
Messages
20
Reaction score
1
Which samp you and your server use?
0.3.7, though the original snippet (the one I posted on the first message) works just fine but catches color codes.
I mean, not even a color code-- it seems to grab the "nt" part off of "oyentes" and shove it into the {FFFFFF} section, which is why it breaks up?
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Why you changed snippet value from 0@ to 15@ ????????????????????
You can't do simple copy paste...
PHP:
0C17: 31@ = strlen 15@
PHP:
:changeString
5@ = FALSE // inbracket
0C17: 31@ = strlen 15@
    for 30@ = 0 to 31@
        0085: 29@ = 15@ // copy pointer
        005A: 29@ += 30@  // add offset make loop
        0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
        if
        003B:   28@ == 1@  // (int)
        then
            5@ = TRUE // inbracket
        end

        if
        5@ == FALSE // inbracket
        THEN
            0A8C: write_memory 3@ size 1 value 28@ virtual_protect 1
            3@ += 1 // move to next address
        END

        if
        003B:   28@ == 2@  // (int)
        then
            5@ = FALSE // inbracket
        end
    end
0A8C: write_memory 3@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0
 

Lukahlyo

Member
Joined
Nov 11, 2018
Messages
20
Reaction score
1
Why you changed snippet value from 0@ to 15@ ????????????????????
Yeah, that's on me. In all fairness, I changed it on the original iteration of this attempt since it wasn't working with either 0@ or 15@, then simply forgot to change it back afterwards.
Thing is, I'd tried to change your value back to 0 on every edit you did. And it wasn't going to work anyway because I changed a second value that was, in the end, the problem:
PHP:
0085: 29@ = 0@ // copy pointer
And I changed it because it said "copy pointer" and assumed it meant "copy the input value" ahkhdkdhkhdhksdhkhds

Well, it's working now! Here's the final iteration I'm going with, in case it's useful to anyone. Thanks a lot Parazitas for your patience hdsjjdjs
PHP:
{$CLEO .cs}

0000:

REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

WHILE TRUE
   WAIT 0


IF
0B61:  samp is_local_player_spawned
THEN
    FOR 10@ = 99 TO 99 // Can be changed to 98 to 99, 97 to 99 - it reads the last amount of lines from the log. In this case, it reads just the last one.
        0AC8: 11@ = allocate_memory_size 260
        0AC8: 12@ = allocate_memory_size 260
        0B75: samp get_chat_string 10@ text_to 11@ prefix_to 12@ color_to 13@ prefix_color_to 14@ // READ CHAT TEXT , ETC..
        0AC8: 15@ = allocate_memory_size 1024
        0AB1: call_scm_func @changeString param_count 4 text 11@ FirstCharacter 123 SecondCharacter 125  memory_to_store_characters_as_text 15@
        IF
        0C29: $NOT_USED = stristr string1 15@ string2 "text" // Text to look for in the chat to start the sequence.
        THEN
                0AF9: samp say_msg "%s" 15@ // Say exactly what was caught from the chat.
                wait 3000
                0AF8: samp add_message_to_chat "{00CC00}Success." color 0xFFFFFF // Avoid endless looping by adding a debug message to the chat.
                wait 3000
        END
    END
END

END


:changeString
5@ = FALSE // inbracket
0C17: 31@ = strlen 0@
    for 30@ = 0 to 31@
        0085: 29@ = 0@ // copy pointer
        005A: 29@ += 30@  // add offset make loop
        0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
        if
        003B:   28@ == 1@  // (int)
        then
            5@ = TRUE // inbracket
        end

        if
        5@ == FALSE // inbracket
        THEN
            0A8C: write_memory 3@ size 1 value 28@ virtual_protect 1
            3@ += 1 // move to next address
        END

        if
        003B:   28@ == 2@  // (int)
        then
            5@ = FALSE // inbracket
        end
    end
0A8C: write_memory 3@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0

Solved, please lock
 
Status
Not open for further replies.
Top