tge-was-taken / Atlus-Script-Tools

A set of tools for working with scripts used in various game developed by Atlus.
GNU General Public License v3.0
65 stars 40 forks source link

PQ2 FlowScript Compile Fails #76

Open AcidicPeridot opened 6 months ago

AcidicPeridot commented 6 months ago

This .bf file from Persona Q2 throws an error when attempting to recompile, even when no changes are made.

Command: "combi01.bf.flow" -Compile -OutFormat V2 -Library PQ2 -Encoding SJ -Hook -SumBits Error:

[04/25/2024 02:53 AM] 4/25/2024 2:53:58 AM  Info: (0103:0000) Compiling procedure: BTL_TAG_RUN
[04/25/2024 02:53 AM] 4/25/2024 2:53:58 AM  Error: (0107:0004) A integer literal is an invalid statement
[04/25/2024 02:53 AM] 4/25/2024 2:53:58 AM  Error: (0104:0000) Failed to emit procedure body
[04/25/2024 02:53 AM] 4/25/2024 2:53:58 AM  Error: One or more errors occured during compilation!
[04/25/2024 02:53 AM] 4/25/2024 2:53:58 AM  Error: One or more errors occured while executing task!
[04/25/2024 02:53 AM] 
AnimatedSwine37 commented 6 months ago

The actual problem is with the decompilation. The procedure ends up as the following when is clearly incorrect and therefore can't be compiled

void BTL_TAG_RUN()
{
    PUTS( "実行" );
    EVT_FUNCTION_0018( 4, 9001 );
    0;
    0;
    UNKNOWN_FUNCTION_12707();
    60;
    1;
    UNKNOWN_FUNCTION_12707();
    140;
    UNKNOWN_FUNCTION_12708();
    300;
    2;
    UNKNOWN_FUNCTION_12707();
    BTL_FUNCTION_0198();
}
lraty-li commented 6 months ago

same problem in event/e800 series .bf files. event/e800/e808_020.bf.flow line 26

......
// Procedure Index: 0
void e808_020()
{
    int var0;
    EVT_FUNCTION_000F( 1 );
    EVT_FUNCTION_0001( -1, -1 );
    EVT_FUNCTION_0017( 1 );
    EVT_SET_USUAL();
    0;
    1;

    if ( UNKNOWN_FUNCTION_-32764() == 8 )
    {
        WND_FUNCTION_000C( 0, 1 );
        WND_FUNCTION_000B( 2 );
        WND_FUNCTION_000B( 3 );
......

and unknown function numer gets negative value, like -32764 of UNKNOWNFUNCTION-32764()

e828_045.zip

oceanstuck commented 3 months ago

Went and did a look with this alongside Peridot. The initial example with UNKNOWN_FUNCTIONs 12707 and 12708 was the result of the library having no functions at their respective ids (0x31a3 and 0x31a4) and was resolved by adding functions of those ids with the correct number of parameters. They appear to both control the displaying of subtitles during Unison Skills, with 12707 displaying a msg at a certain frame and 12708 controlling how long a msg is displayed for.

However, UNKNOWN_FUNCTION_-32764 appears to already be properly defined in the library. From disassembling the assembly, one can see that its id is 0x8004 and it takes two int parameters, corresponding to CAMP_FUNCTION_0004. The decompiler appears to be interpreting the function index (a value that should be unsigned) as signed, as -32764 in hex is -7ffc, the two's complement of which is 8004.

Screenshot_21 Screenshot_4 Screenshot_5