sannybuilder / dev

Sanny Builder Bug Tracker and Roadmap development
https://sannybuilder.com
49 stars 0 forks source link

Opcode 0AA2 shuffled its parameters during Compilation #345

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

Aldrin-John-Olaer-Manalansan commented 2 months ago

I have a script that uses foreign functions from MSAPI, but they are not working. By migrating to Cleo 5, I quickly identified the problem, since 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

Decompiling with Sanny builder 3:

{$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

Decompiling with Sanny builder 4:

{$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 

As you can see, the input parameter and the output parameter got shuffled, it might have something to do with the way opcode parameters are sorted in sanny builder configuration, I don't know which configuration file it is since 4.0.0 release seems to be pretty big and there are so many changes, especially with its new configuration files. How to fix this?

x87 commented 2 months ago

I replied in the other ticket, copying my answer here:


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
Aldrin-John-Olaer-Manalansan commented 2 months ago

I replied in the other ticket, copying my answer here:

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

Thanks for your fast reply, I appreciate the explanation.

This Means that this mode will apply to all scripts that uses opcodes right? Like all their parameters needs to be re-ordered? For my entire life coding cleo scripts I always use opcodes. I have like 100 scripts and all of them have opcodes. It's like you're saying that I need to modify all of them 😢 based on what the Opcode Search Tool opcode syntax: image

Do we have an option that makes the syntax for this parameter arrangement backward compatible?

x87 commented 2 months ago

You can keep using SA 1.0 edit mode to compile old scripts.

I recommend write new scripts in SBL mode. You can also disassemble old scripts using new SBL mode to get params in right order, but you will lose the comments/var names

Aldrin-John-Olaer-Manalansan commented 2 months ago

You can keep using SA 1.0 edit mode to compile old scripts.

I recommend write new scripts in SBL mode. You can also disassemble old scripts using new SBL mode to get params in right order, but you will lose the comments/var names

In this choices: image

According to this: image Does this mean that SA 1.0 edit mode is not available anymore?

x87 commented 2 months ago

I was talking about new SBL modes in SB 4.0

Aldrin-John-Olaer-Manalansan commented 2 months ago

I don't understand how to compile Old Scripts using SA 1.0 edit mode, or how to change to SA 1.0 edit mode.

But so it seems, at the end of the day I'll be migrating the syntax of my scripts to SB 4.0 SBL mode.

x87 commented 2 months ago

I don't understand how to compile Old Scripts using SA 1.0 edit mode, or how to change to SA 1.0 edit mode.

But so it seems, at the end of the day I'll be migrating the syntax of my scripts to SB 4.0 SBL mode.

Switch to GTA SA v1.0 mode using menu in the bottom right corner, then compile. It's available both in 3.X and 4.0 versions

image

Aldrin-John-Olaer-Manalansan commented 2 months ago

Sorry for Replying Late. Thank you for the clarification, I realized that this option pops up when I use an SBL Syntax: image

Since this topic is in conclusion to the new SBL Syntax. I want to confirm some things that don't seemed to be working for me. Can you explain why this is not working? image

{$CLEO}
{$USE file}
0000:

if {8AF0:} not 0@ = read_int_from_ini_file "cleo\myfile.ini" {section} "thissection" {key} "thatkey"
then 0@ = 131071
end

0A93: terminate_this_custom_script
Aldrin-John-Olaer-Manalansan commented 2 months ago

nvm, it must be like this:

{$CLEO}
{$USE file}
0000:

if not {8AF0:} 0@ = read_int_from_ini_file "cleo\myfile.ini" {section} "thissection" {key} "thatkey"
then 0@ = 131071
end

0A93: terminate_this_custom_script