Jump to content

Lineage 2 GF AI Decompiler


Recommended Posts

https://github.com/madyanov/nasc-decompiler/releases

 

Decompiles ai.obj to AST, then converts AST to NASC (but can be converted to any other language, such as Java, etc).

Resulting NASC can be successfully compiled back with Eressea’s compiler.

 

To run, put ai.obj file to current folder and double click on run.bat.

Edited by verbrannt
  • Thanks 4
Link to comment
Share on other sites

Hi, nice work,  but when I try decompile my ai.obj, I get  this:

C:\ep\git\nasc-decompiler>run.bat
Decompile ai_adiantum_skilluse
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
PHP Notice:  Undefined offset: 1 in C:\ep\git\nasc-decompiler\core\tokenizer.php on line 26
Decompile ai_agit02_dietrichPHP Notice:  Undefined index: S1 in C:\ep\git\nasc-decompiler\core\parser.php on line 442
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to StringExpression::__construct() must be of the type string, null given, called in C:\ep\git\nasc-decompiler\core\parser.php on line 442 and defined in C:\ep\git\nasc-decompiler\core\ast.php:195
Stack trace:
#0 C:\ep\git\nasc-decompiler\core\parser.php(442): StringExpression->__construct(NULL)
#1 C:\ep\git\nasc-decompiler\core\parser.php(116): Parser->parsePushString(Object(Token))
#2 C:\ep\git\nasc-decompiler\core\main.php(73): Parser->parseClass(Object(Token))
#3 {main}
  thrown in C:\ep\git\nasc-decompiler\core\ast.php on line 195

Press any key to continue . . .

Am I doing anything wrong? The AI part where it's failing is here http://download.l2shrine.com/ai.obj

 

Link to comment
Share on other sites

KR symbols broken in DebugSay function (affected Freya, H5, GD), example class 'citizen' Event SPELLED

 

DebugSay(" NPC t < D| Xt|.");

Should be

DebugSay("난 NPC에게 감염이 되었으니 좀비를 소환해야겠다.");

 

Edited by ChaosPaladin
Link to comment
Share on other sites

2 minutes ago, ChaosPaladin said:

KR symbols broken in DebugSay function (affected Freya, H5, GD), excample class 'citizen' Event SPELLED

 


DebugSay(" NPC t < D| Xt|.");

Should be


DebugSay("난 NPC에게 감염이 되었으니 좀비를 소환해야겠다.");

 

Known issue. Not critical, and wont be fixed, but you can make PR.

Link to comment
Share on other sites

Thanks, now it works fine. As for utf-16le problem, this should be sufficient (I'm not PHP programmer, I've copied it from https://stackoverflow.com/questions/27551099/how-to-read-from-files-in-utf-16le-encoding-in-php):

...
$tokenizer = new Tokenizer();
$parser = new Parser($data);
$generator = new NASCGenerator();

class readutf16le_filter extends php_user_filter {
    function filter($in, $out, &$consumed, $closing) {
        while ($bucket = stream_bucket_make_writeable($in)) {
            $bucket->data = iconv('UTF-16LE', 'UTF-8',
                strlen($bucket->data) && substr($bucket->data, 0, 2) == "\xff\xfe"
                    ? substr($bucket->data, 2)
                    : $bucket->data);
            $consumed += $bucket->datalen;
            stream_bucket_append($out, $bucket);
        }
        return PSFS_PASS_ON;
    }
}

stream_filter_register('readutf16le', 'readutf16le_filter');

$file = fopen('ai.obj', 'r');
stream_filter_append($file, 'readutf16le');
$line = 0;

// write BOM
file_put_contents('ai.nasc', pack('S', 0xFEFF));
...

and just remove

    $string = preg_replace('/[^\s\x20-\x7E]/', '', $string); // remove non-ASCII characters

 

Edited by eressea
Link to comment
Share on other sites

Hi, good job but you need fix other small bug on all classes than use  "skill_name_id / 256 * 256" you need change from :

 

Quote

/ 256 * 256  to  / (256 * 256)

 

Else some npc ai  doesn't work  as Treasure chest and more.

Link to comment
Share on other sites

50 minutes ago, zconll said:

Hi, good job but you need fix other small bug on all classes than use  "skill_name_id / 256 * 256" you need change from :

 

 

Else some npc ai  doesn't work  as Treasure chest and more.

Thx. Fixed now, checkout the master branch.

Link to comment
Share on other sites

14 minutes ago, eressea said:

May I ask what's the reason of ignoring classes guild_master_test_helper1 and public_wyvern?

 

Decompiler can’t build correct AST for these classes. It fails only with ai.obj from the leaked GF (l2off). With another ai.obj (e.g. from advext) it should work fine.

 

I’ll fix this after releasing support of the leaked Freya AI.

Edited by verbrannt
Link to comment
Share on other sites

Ah, it compiles my classes without problem :)

 

May I offer you a patch for reading UTF-16LE input, optional UTF-8 output support and optional tree structure output support? The last one seems to require newer PHP (works with 7.2.7 and enabled long win32 paths for me)

 

https://pastebin.com/Fir2ZTJd

Edited by eressea
Link to comment
Share on other sites

4 minutes ago, eressea said:

Ah, it compiles my classes without problem :)

 

May I offer you a patch for reading UTF-16LE input, optional UTF-8 output support and optional tree structure output support? The last one seems to require newer PHP (works with 7.2.7 and enabled long win32 paths for me)

 

https://pastebin.com/Fir2ZTJd

Yea, thank you. I will apply your patch.

Only reason I’m using UTF-16LE is to be able to compile result code using your compiler. I though it only supports UTF-16LE.

Link to comment
Share on other sites

2 minutes ago, verbrannt said:

Yea, thank you. I will apply your patch.

Only reason I’m using UTF-16LE is to be able to compile result code using your compiler. I though it only supports UTF-16LE.

 

Yes, it supports only UTF-16LE but I'm using tree structure with UTF-8 files and when I build the AI, I go through the directory structure (so I know which is the correct class order) and join all the files into one big UTF-16LE file, then I let it compile and then I split it again to directory structure (because my extender is able to work with directory structure with UTF-8 obj files).

 

Maybe I'll share the building script but it needs some polishing and cleaning...

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now



×
×
  • Create New...