Skip to content

Instantly share code, notes, and snippets.

@MiranDMC
Last active July 22, 2023 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiranDMC/b18251722d85839e7d1e9d81c7a32f74 to your computer and use it in GitHub Desktop.
Save MiranDMC/b18251722d85839e7d1e9d81c7a32f74 to your computer and use it in GitHub Desktop.
{$CLEO .cs}
0000: NOP
while true
// pass regular string variables as arguments
v$someText = "15_chars_global"
0@s = 'LABEL1'
cleo_call @PRINT_FOUR args 4 v$someText "Some really, really long text" 0@s 'LABEL2'
wait 4000
// call function to modify text variable inplace
cleo_call @TEXT_CUT args 2 v$someText 8 // trim to 8
cleo_call @PRINT_FOUR args 4 "Variable trimmed to 8" v$someText "unused" "unused" // show on screen
wait 4000
// return into short string variable
0209: 0@ = random_int_in_ranges 0 5 // 0-4
cleo_call @TEXT_SELECT_LABEL args 6 0@ 'BANDA11' 'BANDA12' 'BANDA13' 'BANDA14' 'BANDA15' result 1@ 2@ // return into both components of 1@s
cleo_call @PRINT_FOUR args 4 "Selected label" 1@s "unused" "unused" // show on screen
00BA: show_text_styled GXT 1@s time 4000 style 2 // uset the GXT label
wait 4000
// pass pointer to return text buffer
0AC8: 0@ = allocate_memory_size 128
0209: 1@ = random_int_in_ranges 0 6 // 0-5
cleo_call @TEXT_SELECT args 8 0@ 1@ "Zero" "First" "Second" "Third" "Fourth" "Fifth" // output string to specified buffer
cleo_call @PRINT_FOUR args 4 "The selected text is" 0@ "unused" "unused" // show on screen
0AC9: free_allocated_memory 0@
wait 4000
end
// arg 0 - string
// arg 1 - string
// arg 2 - string
// arg 3 - string
:PRINT_FOUR
0AD1: show_formatted_text_highpriority "1: %s ~n~ 2: %s ~n~ 3: %s ~n~ 4: %s" time 10000 0@ 1@ 2@ 3@
cleo_return 0
// arg 0 - text
// arg 1 - new length
:TEXT_CUT
if
0@ == 0 // null pointer
then
cleo_return 0
end
005A: 0@ += 1@
write_memory 0@ size 1 value 0x00 virtual_protect 0 // string terminator
cleo_return 0
// select one from provided GXT labels
// arg 0 - index
// arg 1 - text with index 0
// arg 2 - text with index 1
// arg x - ...and so on
// return 0-1 - selected text label
:TEXT_SELECT_LABEL
// obtain pointer to selected text
0AC7: 31@ = var 1@ pointer // first text
0@ *= 4 // 4 bytes peer argument
005A: 31@ += 0@
read_memory 31@ = from 31@ size 4 virtual_protect 0
string_format 0@s = "%s" 31@ // copy str into local variable(s)
cleo_return 2 0@ 1@ // pass both components of short string. Returning long string 0@v would need 4 elements
// select one from provided strings
// arg 0 - output text buffer pointer
// arg 1 - index
// arg 2 - text with index 0
// arg 3 - text with index 1
// arg 4 - and so on...
:TEXT_SELECT
if
0@ == 0 // null output pointer
then
cleo_return 0
end
0AC7: 31@ = var 2@ pointer // first argument
1@ *= 4 // 4 bytes peer argument
005A: 31@ += 1@
read_memory 31@ = from 31@ size 4 virtual_protect 0 // get ptr to the text
string_format 0@ = "%s" 31@
cleo_return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment