verbrannt Posted July 13, 2018 Posted July 13, 2018 (edited) 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 July 15, 2018 by verbrannt 4 Quote
eressea Posted July 14, 2018 Posted July 14, 2018 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 Quote
verbrannt Posted July 14, 2018 Author Posted July 14, 2018 (edited) Hi, thx for feedback. I just fixed this, you can pull from master. Edited July 14, 2018 by verbrannt Quote
ChaosPaladin Posted July 14, 2018 Posted July 14, 2018 (edited) 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 July 14, 2018 by ChaosPaladin Quote
verbrannt Posted July 14, 2018 Author Posted July 14, 2018 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. Quote
eressea Posted July 14, 2018 Posted July 14, 2018 (edited) 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 July 14, 2018 by eressea Quote
zconll Posted July 14, 2018 Posted July 14, 2018 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. Quote
verbrannt Posted July 14, 2018 Author Posted July 14, 2018 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. Quote
zconll Posted July 14, 2018 Posted July 14, 2018 nice, you have one missing handler " handler 164 SOCIAL_ACTION_EVENT ". Quote
eressea Posted July 14, 2018 Posted July 14, 2018 May I ask what's the reason of ignoring classes guild_master_test_helper1 and public_wyvern? Quote
verbrannt Posted July 14, 2018 Author Posted July 14, 2018 (edited) 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 July 14, 2018 by verbrannt Quote
eressea Posted July 14, 2018 Posted July 14, 2018 (edited) 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 July 14, 2018 by eressea Quote
verbrannt Posted July 14, 2018 Author Posted July 14, 2018 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. Quote
eressea Posted July 14, 2018 Posted July 14, 2018 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... Quote
eressea Posted July 14, 2018 Posted July 14, 2018 Sorry for doublepost, one more question, I keep getting av_quest0 instead of myself.av_quest0, any idea what can be wrong? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.