Scr to Lua decompiler?

Discuss anything that is related to OpenArcanum.
Laz
Bunny
Bunny
Posts: 2
Joined: Mon Oct 18, 2010 9:29 am
Location: Russia

Re: Scr to Lua decompiler?

Post by Laz » Mon Oct 18, 2010 10:29 am

Hello!

I think there is an easy way to handle all those gotos. When scr-decompiler parses file, it:
reads line
translates it to some lua code
writes result
When it sees goto statement, it just goes to that line and continues processing from it. When it sees return statement, it returns to line, where goto was called.

I wrote a really simple parser (about 50 SLOC in python), which processes only if and goto statements. You can see result here: http://dpaste.com/259534/ (I used file from http://pastebin.com/AYF6fC7s). Obviously, it's not correct (if statements must be processed other way, loop statement is not processed at all), but it's somehow readable and can be edited by hands.

User avatar
Crypton
Arronax's Best Friend
Arronax's Best Friend
Posts: 420
Joined: Wed Jul 08, 2009 5:04 am
Location: Abyss
Contact:

Re: Scr to Lua decompiler?

Post by Crypton » Mon Oct 18, 2010 1:09 pm

Hi Laz,

thank you very much, now I realize why there is so much "return and SKIP default" statements, those goto statements are actually function calls to subfunctions, so your conversion is correct.
(But what should happen if there is "return and run default"? Whats default anyway?)

I'll modify that decompiler to handle goto statements as you described. Thanks again ;)

P.S. Actually I didn't know that you can return from goto statement, I thought that its simply jump to some code. Also I must admit that I don't know much about scr sctipts, like those local and script flags, counters... I don't know their purpose either, and we will need to convert them to something more usable and coder friendly. Any ideas?:)

DDTerr
Bunny
Bunny
Posts: 2
Joined: Mon Oct 18, 2010 5:23 pm
Location: Praha
Contact:

Re: Scr to Lua decompiler?

Post by DDTerr » Mon Oct 18, 2010 5:51 pm

Crypton wrote:
P.S. Actually I didn't know that you can return from goto statement, I thought that its simply jump to some code. Also I must admit that I don't know much about scr sctipts, like those local and script flags, counters... I don't know their purpose either, and we will need to convert them to something more usable and coder friendly. Any ideas?:)
Hi Crypton,

I think you should read the following documents and try to understand as many text from these documents as possible... I can confirm it is very hard to do. Also some kind of SCR and DLG modding experience would be necessary. I can help with some if you need.
Documents for SCR and DLG modding:
WorldEdManual.pdf from page 69 to 108 or ALL pages :-)
editdocs.zip

Some explanation:
"dialog (num)" - initiates PC-NPC dialog associated to this script (with the same number as this SCR file) on line number "num"
"call script (num) at line (num2) with triggerer (obj) and attachee (obj2)" ... you will have to index all calls to lines in scripts before any conversion!!, then make some labels in the new script files to able to track them and then to create new calls in the new scripting language ... a huge amount of work!

If you need, write me a private message in Czech so we can explain our things better in native language and then the results public here in English.
DDTerr.

Unofficial patch for Czech version of Arcanum:
http://www.volny.cz/ddterr

User avatar
Crypton
Arronax's Best Friend
Arronax's Best Friend
Posts: 420
Joined: Wed Jul 08, 2009 5:04 am
Location: Abyss
Contact:

Re: Scr to Lua decompiler?

Post by Crypton » Mon Oct 18, 2010 6:53 pm

DDTerr wrote:Hi Crypton,
Long time no see, DDTerr...
I think you should read the following documents and try to understand as many text from these documents as possible... I can confirm it is very hard to do. Also some kind of SCR and DLG modding experience would be necessary. I can help with some if you need.
Documents for SCR and DLG modding:
WorldEdManual.pdf from page 69 to 108 or ALL pages :-)
editdocs.zip
Wow, I think that I've seen these documents before, but I actually did not read them, because I'm so lazy when it comes to reading something, and thats why I never read any book till end. Thank you for reminding me that documents, I should definitely read those, it will make a lot of things clear to me, I'm sure, but I just only hope that it won't hurt... much, hehe :D
Some explanation:
"dialog (num)" - initiates PC-NPC dialog associated to this script (with the same number as this SCR file) on line number "num"
"call script (num) at line (num2) with triggerer (obj) and attachee (obj2)" ... you will have to index all calls to lines in scripts before any conversion!!, then make some labels in the new script files to able to track them and then to create new calls in the new scripting language ... a huge amount of work!
I see, the dialog statement is now clear for me, but that second one, still don't have a clue... I will re-read your description after reading that documents, I hope that it will become more clear to me after that.
If you need, write me a private message in Czech so we can explain our things better in native language and then the results public here in English.
Thank you for the offer. I would definitely welcome your knowledge and skills if needed, but at this moment, I should read that docs before continuing in work on scr decompiler.

Thanks again, see you later ;)

Laz
Bunny
Bunny
Posts: 2
Joined: Mon Oct 18, 2010 9:29 am
Location: Russia

Re: Scr to Lua decompiler?

Post by Laz » Mon Oct 18, 2010 7:00 pm

I have found this documentation on Arcanum World Editor: http://www.terra-arcanum.com/amtut/reso ... manual.htm . Looks like it is most complete description of arcanum resource files publicly available (but I did not google too much). As I understand, each script has some attachment point - something, that triggers it, and script can override result of that action. For example, when character picks up an item, a script can be called. And it can return and RUN default or SKIP default, that means execute or not that action (pick up item or not).

Actually, after reading some docs, I think that arcanum script language is primitive but complex - for me it looks like assembler. Digits and letter codes instead of variables and dialog names, gotos, a script can call any script at any line etc. Lua is beatifull and expressive language, and translating all those scripts one-to-one to lua will nullify all of it's features. I think, there must be some lua API, which can be used to write game scripts, and then some program will translate scr files to lua-scripts, which will use that API.

Post Reply