[SNIPPET] Copy a String

//0AB1: call @copy_string 4 text 0@ start 0 end 9 to_buffer 1@
:copy_string
var
    1@: int
    2@: int
    4@: int
    5@: int
end
if 1@ < 0
then
    059A: return_false
    ret 0
end
0C17: 5@ = strlen 0@
if 2@ > 5@
then
    2@ = 5@
end
if 5@ <= 0
then
    059A: return_false
    ret 0
end
if 2@ < 1@
then
    059A: return_false
    ret 0
end
if 1@ >= 1
then
    for 4@ = 0 to 1@
    inc(0@)
    end
end
2@ -= 1@
inc(2@)
0C10: memcpy destination 3@ source 0@ size 2@
0485: return_true
ret 0
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
100% working without SAMPFUNCS
PHP:
:copy_string
{
    0AB1: call @copy_string 4 text 0@ start 0 end 9 to_buffer 1@
}
var
    1@: int
    2@: int
    4@: int
    5@: int
end
if 1@ < 0
then
    059A: return_false
    0AB2: ret 0
end
0AB1: @strlen 1 string 0@ rtn 5@
if 2@ > 5@
then
    2@ = 5@
end
if 5@ <= 0
then
    059A: return_false
    0AB2: ret 0
end
if 2@ < 1@
then
    059A: return_false
    0AB2: ret 0
end
if 1@ >= 1
then
    for 4@ = 0 to 1@
    inc(0@)
    end
end
2@ -= 1@
inc(2@)
0AB1: @memcpy 3 destination 3@ source 0@ size 2@
0485: return_true
0AB2: ret 0

:strlen
{
    Example: 0AB1: @strlen 1 string 1@ return: 3@
    In: 0@ - text;
    Out: 1@ - size;
}
for 1@ = 0 to 1024
    0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
    if not 2@ == 0
    jf break
    0@ += 1
end
0AB2: ret 1 1@

:memcpy

var
0@ : integer
1@ : integer
2@ : integer
3@ : integer
end

// 0@ - destination, 1@ - source, 2@ - size
// Example: 0AB1: @memcpy 3 destination 6@ source 3@ size 5@

dec(2@)
for 3@ = 0 to 2@
    0A8D: 4@ = read_memory 1@ size 1 virtual_protect 0
    0A8C: write_memory 0@ size 1 value 4@ virtual_protect 0
    1@ += 1
    0@ += 1
end

0AB2: ret 0
 
Last edited:
Top