cleolibrary / CLEO5

CLEO 5 for GTA San Andreas
https://cleo.li
MIT License
48 stars 5 forks source link

not working properly? 0A99: set_current_directory 1 #178

Closed Aldrin-John-Olaer-Manalansan closed 1 month ago

Aldrin-John-Olaer-Manalansan commented 1 month ago

I have a script that is supposed to create a folder tree inside %Documents%\GTA San Andreas User Files folder:

{$CLEO}
0000:

const
    LIB_KERNEL32 = 27@

    LIB_SHLWAPI = 26@
    PROC_PATHFILEEXISTSA = 25@
end

if or
    8AA2: not LIB_KERNEL32 = load_dynamic_library "Kernel32.dll"
    8AA2: not  LIB_SHLWAPI = load_dynamic_library  "Shlwapi.dll"
then 0A93: terminate_this_custom_script
end
if 8AA4: not PROC_PATHFILEEXISTSA = get_dynamic_library_procedure "PathFileExistsA" library LIB_SHLWAPI
then 0A93: terminate_this_custom_script
end

0A99: set_current_directory 1 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~USER Directory
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~End of Initialization~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Create Backup Directory if not exist
0AC6: 2@ = label @ChatLogBackupPath pointer

0AA7: _PathFileExistsA PROC_PATHFILEEXISTSA num_params 1 pop 0 _pszPath 2@ _Return_bPathExists 1@
if 1@ <> true // path does not exists
then
    if 0AA4: 1@ = get_dynamic_library_procedure "CreateDirectoryA" library LIB_KERNEL32
    then
        0AA7: _CreateDirectoryA 1@ num_params 2 pop 0 _lpSecurityAttributes 0 _lpPathName 2@ _Return_bIsSuccess 3@
        if 3@ <> false // succeeded
        then 0ACD: show_text_highpriority "~y~Created Backup Directory" time 10000
        else 0ACD: show_text_highpriority "~r~Failed to Create Backup Directory!" time 10000
        end
    end
end
    //

0A93: terminate_this_custom_script

:ChatLogBackupPath
hex
    "SAMP\\ChatLogs\\\0"
end

I'm expecting this script to create folder structure like this: %Documents%\GTA San Andreas User Files\SAMP\ChatLogs

But the script creates the folders inside the GTA Game Root Folder: %GTASA Game Folder%\SAMP\ChatLogs

According to Opcode Database Documentation: image I tried passing a value of 0 or 1 at opcode 0A99 but it still does not set working directory at gtasa user files folder.

This is strange because at cleo 4.4.1, opcode 0A99 is working properly. But in Cleo 5, it doesn't work the way I want it to be. Any Ideas how to fix it without specifying the entire absolute path? 0A99: set_current_directory "C:\Users\mypc\Documents\GTA San Andreas User Files"

MiranDMC commented 1 month ago

As mentioned in release log opcode 0A99 is no longer modifying game's working directory. Why do you mix build in opcodes with native function call of CreateDirectoryA? There is create_directory opcode in CLEO and it will work as expected with 0A99 used within same script. resolve_path opcode can be used to obtain absolute path if there is need for it.

Modified application working directory crashes game whenever it tries to load in some resources, as it expects it to be set to game root.

Aldrin-John-Olaer-Manalansan commented 1 month ago

As mentioned in release log opcode 0A99 is no longer modifying game's working directory. Why do you mix build in opcodes with native function call of CreateDirectoryA? There is create_directory opcode in CLEO and it will work as expected with 0A99 used within same script. resolve_path opcode can be used to obtain absolute path if there is need for it.

Modified application working directory crashes game whenever it tries to load in some resources, as it expects it to be set to game root.

How can I resolve filepath to gta sa user directory? Can you help me fix this code?

{$CLEO}
{$USE file}
0000:

// 0A99: set_current_directory 1 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~USER Directory
0@ = Fs.ResolvePath("GTA San Andreas User Files")
0ACD: show_text_highpriority "path~n~%s" time 10000 0@
wait 10000
    // Create Backup Directory if not exist
0AC6: 2@ = label @ChatLogBackupPath pointer
if 8AE4: not does_directory_exist 2@
then
    if 0AE5: create_directory 2@ // succeeded
    then 0ACD: show_text_highpriority "~y~Created Backup Directory" time 10000
    else 0ACD: show_text_highpriority "~r~Failed to Create Backup Directory!" time 10000
    end
end
    //

0A93: terminate_this_custom_script

:ChatLogBackupPath
hex
    "SAMP\\ChatLogs\0"
end
Aldrin-John-Olaer-Manalansan commented 1 month ago

Modified application working directory crashes game whenever it tries to load in some resources, as it expects it to be set to game root.

It only crashes when the script does not put the working directory back to the root folder. But this workaround fixes the crashing problem at opcode 0A99:

Cleo 4.4.4:

{$CLEO}
{$USE file}
0000:

0A99: set_current_directory 1 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~USER Directory
    // Create Backup Directory if not exist
0AC6: 2@ = label @ChatLogBackupPath pointer
if 8AE4: not does_directory_exist 2@
then
    if 0AE5: create_directory 2@ // succeeded
    then 0ACD: show_text_highpriority "~y~Created Backup Directory" time 10000
    else 0ACD: show_text_highpriority "~r~Failed to Create Backup Directory!" time 10000
    end
end
0A99: set_current_directory 0 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Root Directory
    //

0A93: terminate_this_custom_script

:ChatLogBackupPath
hex
    "SAMP\\ChatLogs\0"
end
x87 commented 1 month ago

In CLEO5 you should be able to refer to the folder using virtual path prefix user:\ that resolves to your user settings folder:

{$CLEO}
{$USE file}

// Create Backup Directory if not exist
if not does_directory_exist "user:\\SAMP\\ChatLogs"
then
    if create_directory "user:\\SAMP\\ChatLogs"  // succeeded
    then print_string_now "~y~Created Backup Directory" time 10000
    else print_string_now "~r~Failed to Create Backup Directory!" time 10000
    end
end
terminate_this_custom_script
Aldrin-John-Olaer-Manalansan commented 1 month ago

In CLEO5 you should be able to refer to the folder using virtual path prefix user:\ that resolves to your user settings folder:

{$CLEO}
{$USE file}

// Create Backup Directory if not exist
if not does_directory_exist "user:\\SAMP\\ChatLogs"
then
  if create_directory "user:\\SAMP\\ChatLogs"  // succeeded
  then print_string_now "~y~Created Backup Directory" time 10000
  else print_string_now "~r~Failed to Create Backup Directory!" time 10000
  end
end
terminate_this_custom_script

Exactly what I need, Thank you!