cleolibrary / CLEO5

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

0AA2 load_dynamic_library does not work #177

Closed Aldrin-John-Olaer-Manalansan closed 3 months ago

Aldrin-John-Olaer-Manalansan commented 3 months ago

I have a script that uses foreign functions from MSIAPI. They are working properly on Cleo 4.4.1, but after I migrated to Cleo 5 then this error message shows up: image

I have come up with a very simple test script that only tries to execute Opcode 0AA2 with conditions:

{$CLEO}
0000:

if 8AA2: not 0@ = load_dynamic_library "Kernel32.dll"
then 0A93: terminate_this_custom_script
end

0A93: terminate_this_custom_script

Sanny builder 3 correctly decompiles it:

{$CLEO .cs}

0000: NOP
00D6: if 
8AA2:   not "Kernel32.dll" = load_dynamic_library 0@ // IF and SET
004D: jump_if_false @Noname_34
0A93: terminate_this_custom_script

:Noname_34
0A93: terminate_this_custom_script

and Sanny builder 4 as well correctly decompiles it:

{$CLEO .cs}

0000: nop 
00D6: if 
8AA2:   not load_dynamic_library {fileName} 0@ {var_handle} "Kernel32.dll"
004D: goto_if_false @Noname_34
0A93: terminate_this_custom_script 

:Noname_34
0A93: terminate_this_custom_script 

So I'm sure that Cleo 5 has the issue.

Take note that I didn't use any DLL Procs for this test because I find it unecessary to test as well, since the failure happens when the DLL gets loaded.

Using this cleo script, Error message pops up, while ingame a red error message overlay is at the top of the screen.

Single Player: image

SAMP image

This confirms that opcode 0AA2 doesn't work the way it should be. Or maybe I'm using it wrong?

Aldrin-John-Olaer-Manalansan commented 3 months ago

I take it back 🤦 , Sanny builder 4 messed up the arrangement of the opcode's parameters, wtf?

x87 commented 3 months ago

In new SBL modes all opcodes have their arguments in the original conventional order: all inputs first, outputs after. 0AA2 had their params re-ordered in legacy SA 1.0 mode.

Quick solution: don't use opcode syntax in new SBL mode. Sanny will correctly arrange params in all commands:

{$CLEO}
nop

if not 0@ = load_dynamic_library "Kernel32.dll"
then terminate_this_custom_script
end

terminate_this_custom_script
MiranDMC commented 3 months ago

Yep, error message clearly informs you that input parameters is invalid. Decompiled code shows you switched arguments around. This script is not working in CLEO4 too, but it just fails in silence. I'm surprised it is not crashing, but it would anyway if the (not)loaded library was put to use later.