Resource icon

Untagged Release HotReload (beta)| Auto reload edited CLEO script

Status
Not open for further replies.

JaggerJam

Active member
Joined
Sep 14, 2017
Messages
98
Solutions
1
Reaction score
21
Inspired from the new CLEO Redux https://github.com/cleolibrary/CLEO-Redux which monitors new changes from CLEO files and reloads them in game.

How it works:
-In a array goes all found files from CLEO folder
-Then in loop I read the threads names of loaded scripts
-Checking the names of threads and filenames to be almost identical, if not then it will not be saved in .ini
-Then the saved filenames are checked real-time size and compares with the size saved in .ini
-Reloading script with 0C6e: and printing SF command with 0C62: "cs filename.cs"


*Thread "sensitive" > if script thread is named differently with 03A4: then it will not save in the array.

Commands:
[/hotcs] - ON/OFF
[/loadcs] - to load new scripts


Demonstration:



WARNING > It is kinda buggy, so it does need some improvments.

Known bugs:
-Not reloading correctly scripts from modloader


Download: https://github.com/JaggerJam69/MyScripts/raw/master/hotreload.cs

JavaScript:
{$CLEO .cs}
{$INCLUDE SF}
{$USE SAMPFUNCS}
{$USE ini}
{$USE bitwise}
{$USE file}
0000:

{
Compiled with SannyBuilder 3.8.0 - custom SDK
Author: Kristyan#7596
}

repeat
wait 0
until SAMP.Available()


0b34: "hotcs" @cleo
0b34: "loadcs" @test

var
12@ : integer
24@ : integer
end


alloc 3@ 64
0C11: memset destination 3@ value 0 size 64
if 0AAB:   does_file_exist "CLEO\hotreload.ini"
then
    0B00: delete_file "CLEO\hotreload.ini"  // IF and SET
end
0ab1: @init_Scripts 0 0@ 1@
log "[HotReload] Found threads: %d" 1@

6@ = 0


while true
wait 0

    if and
    not 1@ == 0
    6@ == 1
    then
        //===================--HotReload loop--===================
        alloc 25@ 128
        alloc 26@ 128
       
        0AA2: 22@ = load_library "Kernel32.DLL"
        0AA4: 21@ = get_proc_address "GetPrivateProfileStringA" library 22@
        0AA4: 20@ = get_proc_address "WritePrivateProfileStringA" library 22@
       
        for 27@ = 0 to 1@
        wait 0
            0C1F: 26@ = string_array 0@ element 27@ size 128
            format 25@ "CLEO\%s" 26@
            if 0A9A: 23@ = open_file 25@ mode "rb"  // IF and SE
            then
                alloc 11@ 128
                0A9C: 24@ = file 23@ size  
                0AA7: call_function {GetPrivaterProfileStringtn}21@ num_params 6 pop 0 | {lpFileName}"CLEO\hotreload.ini" {nSize}128 {lpReturnedString}11@ {lpDefault}"ERROR" {lpKeyName}26@ {lpAppName}"Scripts" | {Result}7@
                0AD4: $NOT_USED = scan_string 11@ format "%d %p" 12@ 4@ // IF and SET
                //Checking size of the script and from saved data in .ini
                if 12@ <> 24@
                then
                    alloc 10@ 64
                             
                    chatmsg "Script reloaded: %s 0x%p"  -1 26@ 4@      
                   
                    format 3@ "cs %s" 26@
                    0C62: exec_console_command 3@
                    0C6E: destroy_custom_thread 4@
                    0A8D: 4@ = read_memory 0xA8B42C size 4 virtual_protect 0
                    format 10@ "%d %p" 24@ 4@
                    0AA7: call_function {WritePrivaterProfileStringtn}20@ num_params 4 pop 0 | {lpFilename}"CLEO\hotreload.ini" {lpString}10@ {lpKeyname}26@ {lpAppname}"Scripts" | 32@ {result}              
                   
                    free 10@
                    break          
                end
                free 11@
            end
            0A9B: close_file 23@
            0C11: memset destination 25@ value 0 size 64  
        end
        0AA3: free_library 22@
        free 25@
        free 26@
     
    end
    // log "%d" 6@
   

END{WHILE}

:test
if 0AAB:   does_file_exist "CLEO\hotreload.ini"
then
    0B00: delete_file "CLEO\hotreload.ini"  // IF and SET
end
free 0@
1@ = 0
0ab1: @init_Scripts 0 0@ 1@
log "[HotReload] Found scripts: %d" 1@
SAMP.CmdRet()


:cleo
0B12: 6@ = 6@ XOR 1
if 6@ == 0
then
    print "~r~Hotloader OFF" 1000
else
    print "~g~Hotloader ON" 1000
end

SAMP.CmdRet()

:init_Scripts
alloc 31@ 10000 //scripts list
0C11: memset destination 31@ value 0 size 10000
alloc 30@ 128 //filename
alloc 26@ 128
alloc 25@ 128
28@ = 0 //file counter


//===================--Format array with scripts names--===================
if 0AE6: 29@ = find_first_file "CLEO\*.cs" get_filename_to 30@
then
    repeat
    wait 0

        0C20: string_array 31@ element 28@ size 128 = 30@
        28@ += 1
   
    until 8AE7: 30@ = find_next_file 29@
    0AE8: find_close 29@
else
    chatmsg "No scripts found" -1
    ret 2 0 0
end
                     
28@ -= 1
19@ = 0    
0AA2: 22@ = load_library "Kernel32.DLL"
0AA4: 21@ = get_proc_address "WritePrivateProfileStringA" library 22@
//better then 0AF5


//===================--FOR loop to compare thread names with found scripts list--===================
for 27@ = 0 to 28@
wait 0
    0C1F: 26@ = string_array 31@ element 27@ size 128
    6@ = 0
   
    0A8D: 4@ = read_memory 0xA8B42C size 4 virtual_protect 0 //Found this memory in cleo.ahk dumper, idk if it is from CLEO or gta_sa.exe
    0085: 5@ = 4@
    5@ += 8 //Thread name of current pointer
     
    format 25@ "CLEO\%s" 26@
    if 0A9A: 23@ = open_file 25@ mode "rb"  // IF and SET
    then
        alloc 18@ 64
     
        if 0c29: -1 = stristr 26@ 5@
        then
            6@ = 1
        else
            0C24: strncpy destination 18@ source 26@ size 7
            //log "%s %s" 18@ 26@
            repeat
            wait 0
            0A8D: 4@ = read_memory 4@ size 4 virtual_protect 0
           
            if not 4@ == 0
            then
                0085: 5@ = 4@
                5@ += 8
                   
                if 0c29: -1 = stristr 18@ 5@
                then
                    6@ = 1
                    break
                end
            end

            until 4@ == 0
         end            
   
        //===================--Write script name/size/pointer in .ini--===================
        if 6@ == 1
        then
            0C20: string_array 31@ element 19@ size 128 = 26@
            19@ += 1
            alloc 3@ 128
            0C11: memset destination 3@ value 128 size 0
            0A9C: 24@ = file 23@ size            
            //log "%s %d" 26@ 24@
            format 3@ "%d %p" 24@ 4@
            0AA7: call_function 21@ num_params 4 pop 0 | {lpFilename}"CLEO\hotreload.ini" {lpString}3@ {lpKeyname}26@ {lpAppname}"Scripts" | 20@ {result}      
            free 3@
        end
        free 18@              
    end
    0A9B: close_file 23@
    0C11: memset destination 25@ value 0 size 64  
end
0AA3: free_library 22@

free 30@
free 26@
free 25@
ret 2 31@ 19@
 
Last edited:
Status
Not open for further replies.
Top