Need help with usecode

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Need help with usecode

Post by artaxerxes »

Hi all,

as some of you know we are trying to translate SI in french (we is Artaxerxes and KlownK).

Thanks to Nadir, who oriented us to the proper files to translate, we've got most of text.flx translated and repacked, ready for distribution.

Now, we would like to start peeking at usecode but I must confess I am a bit lost with usecode.

First of all, should we use wud/wuc or ucdump ?
What is the difference?

How to extract the right usecode function, translate and repack into usecode?

Thanks for the info. We'll be proud to announce a finished SI_f, well, When It's Done (r) (tm)!

Artaxerxes
SB-X
Posts: 980
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by SB-X »

You should use ucxt and ucc.
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by wjp »

ucc doesn't support the full language produced by ucxt yet, so that isn't an option for now.
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by wjp »

The following should do the trick: (in bash, assuming the appropriate files are in the current directory. Also, you'll need a very recent CVS for both rip and wuc)

$ ./rip all
$ for i in `ls *.uco`; do ./wud $i -a > `basename $i .uco`.uc; done

(edit all the .uc files produced)

$ for i in `ls *.uc`; do ./wuc $i `basename $i .uc`.uco; done

(this will produce some warnings most likely. (one for each loop encountered). You should be able to safely ignore them)
$ ./rip glue
This should then have produced a new 'usecode' file.

To make working with accents easier, it might be nice to make wuc translate accented characters from 'normal' codes to the codes U7 uses, so you can edit the .uc files in any editor without needing manual post-processing

Have fun :-)

-Willem Jan
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by wjp »

Oh, a couple of notes on translating conversations:

make sure you translate the conversation keywords to exactly the same word/sentence for each occurence.
Also, you can't give two different keywords the same translation. (The original even screwed up here somewhere. IIRC, it was something with 'liquor' being meant as 2 different keywords)
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

thanks a lot wjp

I'll try that ASAP and report here about the success of the task (or lack of).

Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Another point about Exult.

whenever I get the CVS and compile it, and whatever options I put, it ALWAYS refuses to continue compiling since I don't have libglade installed on my machine.

Is it possible to adjust the configure script so that when libglade is not detected, then it doesn't try to compile stuff needing libglade? (like mapedit).

Thanks a bunch

Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Update on decompiling/recompiling usecode:

I've tried Willem's suggestions and here are the result:

rip all; rip glue => works great
rip all; wud -s xxx -a > xxx.uc; wuc -s xxx.uc xxx ; rip glue => fail

basically, a recompiled function looks different from the normal version even if I make no changes. sbx noticed a pop/push error and until then there is nothing I can do.

Artaxerxes
Darke
Site Admin
Posts: 173
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by Darke »

EXECUTIVE SUMMARY:

Fnord!

MORE DETAILED EXPLANATION:

Even if it works, then there are a number of hurdles you need to overcome:

1) You can't increase the length of _any_ of the data entries, unless you wish
to:

1a) Manually recalculate the offsets, and make the appropriate modifications to
the usecode following, for every string listed after the one you're modifiying.

1b) Alter the dataoffset to be the now 'correct' length, since you've added
bytes. OTOP, looking at the code to wuc it appears to do the 'sane' thing here.

2) You can decrease the length of the data entries, by either space padding, or
adding a 'new' completely empty space string, similar to the other entries, and
correctly terminating the original, now shorter, string.

3) If you need to modify the opcodes, for any reason, you need to be aware,
that:

3a) Adding any opcodes, requires you to manually update all jump targets as
well.

3b) You can however, avoid this, if you're only replacing an opcode with another
opcode of the same length, for example, replacing a `jne 0000` with a `jmp
0000`, or similar.

3c) Again, recalculating the 'code size' value, but this does appear to happen
automatically.

4) IIRC there are other problems as well, but I haven't touched wuc/wud for the
better part of two years. *grin*

However...

i) If someone gets wuc to work again...

ii) If you can understand, and modify, something that looks like the
following...

[trans]
[0x0096]
[0x0000]
`@The sails must be furled before the planks are raised.@`
[/]
[0x0039]
`@I think the gangplank is blocked.@`
[/]
[/]
[0x009F]
[0x0000]
`am`
[/]
[0x0003]
`pm`
[/]
[0x0006]
`am`
[/]
[0x0009]
`0`
[/]
[0x000B]
` `
[/]
[0x000D]
`:`
[/]
[/]
[/]

(With proper pointy braces (greater then/less then signs), rather then [], I
don't know how well this forum is at escaping them.)

iii) If you cross your claws and wait about a week until I can tell you if I can
persuade ucxt to DTRT, or commit code that works...

... I _might_ be able to get ucxt to do all the dirty work relating to all the
above calculations.

Darke

PAWNOTE: I hate the forum's 'reply' box, it's icky, and Just Too Small(tm) for
me to type most of my replys in, I'm lucky cut&paste works... *grin*
Darke
Site Admin
Posts: 173
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by Darke »

As expected, forum didn't keep the tab/space indent for that 'trans' code, let's try again with 'pre' html tags, it is 'nicely' indented though... *grin*


[trans]
[0x0096]
[0x0000]
`@The sails must be furled before the planks are raised.@`
[/]
[0x0039]
`@I think the gangplank is blocked.@`
[/]
[/]
[0x009F]
[0x0000]
`am`
[/]
[0x0003]
`pm`
[/]
[0x0006]
`am`
[/]
[0x0009]
`0`
[/]
[0x000B]
` `
[/]
[0x000D]
`:`
[/]
[/]
[/]
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by drcode »

Sounds like our assembler/disassembler pair are missing something. One should be able to write assembly without specifying numerical offsets; the assembler itself should calculate that.
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Great news!

it now works! Willem has fixed wuc/wud so that we know can start the usecode translation!

THIS IS AWESOME!
Thanks to the whole exult team


Screenshots at
www.serpentisle.fr.st

or at
artaxerxes_2.tripod.com

(french screenshot of conversation soon to come)

Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

As you can see at www.serpentisle.fr.st (screenshots section), I have a problem with some of usecode translation.

When Renfry asks me if I am a stranger, usecode automatically puts "yes no" without having any "yes no" in the function 0449 (renfry's function).

I notice it calls a calli _item_say@2 (004d)

I suspect that is where I would find the "yes no" string but how do I access it?

Thx for the help


Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Colourless helped me with that.

In fact the YES NO thing is in 0955 which is called in 0449.

It is fixed and works like a charm now.

thx again
Artaxerxes
Paulon

Re: Need help with usecode

Post by Paulon »

Looks good to me, though I've long since forgotten my rudimentary French skills. Congrats on the progress.
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by drcode »

Cool! Er, I mean, froid.
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Maybe the exult team will consider putting a link to our site when we are finished with the translation !?!

(if you plan to do this, please wait that we got more usecode translated!)

Thx

Artaxerxes
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by wjp »

Sure. Let me know when you want me to add it.
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

Another question about usecode:


as most people know, and as a previous post in the forum indicated, exult uses a 12 hour clock because of a programming hack. In fact, the engine runs a 24 hour clock and everytime a time source (pocketwatch, grand father clock, etc) is used, a usecode function (I think) transforms it into a 12 hour clock for those anglo-saxon players! :)

Since latin people (and others) use 24h, where should I hack to make it show 24 hours when a time source is d-clicked ?

I do believe this is a usecode issue but if I am wrong, please indicate if it is then an exult specific function.

Thanks for your help!

Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

I'd like to add another one about usecode:

I'm studying the usecode function for the tim in both BG and SI (english).

Once I deassemble the usecode function of BG (009F), I've got this:

0008: 38 38 00 00 callis _UNKNOWN@0 (0038)
000C: 12 00 00 pop [0000]
000F: 1D 00 00 pushs L0000 ; am
0012: 12 01 00 pop [0001]
0015: 21 00 00 push [0000]
0018: 1F 0C 00 pushi 000CH ; 12

...

0045: 38 39 00 00 callis _play_music@0 (0039)
0049: 12 02 00 pop [0002]
004C: 21 02 00 push [0002]
004F: 1F 09 00 pushi 0009H ; 9
0052: 19 cmple



On the other hand, the SI version is:
05E5: 05 CA 00 jne 06B2
05E8: 38 45 00 00 callis _game_hour@0 (0045)
05EC: 12 1E 00 pop [001E]
05EF: 1D 63 03 pushs L0363 ; am
05F2: 12 1F 00 pop [001F]
05F5: 21 1E 00 push [001E]
05F8: 1F 0C 00 pushi 000CH ; 12

...

0635: 38 46 00 00 callis _game_minute@0 (0046)
0639: 12 20 00 pop [0020]
063C: 21 20 00 push [0020]
063F: 1F 09 00 pushi 0009H ; 9



I suspect thus that the BG version has a problem. Function 38 is game_hour and function 39 is game_minutes and not play_music.

Also, how many registers are used ? or maybe it is a heap ? In this case, the cmp instruction pop naturally twice and then compare. I must say I'm a bit lost when I read something like

05EF: 1D 63 03 pushs L0363 ; am
05F2: 12 1F 00 pop [001F]


What's the point in pushing something if you pop it up right after?

Thx for the help

Artaxerxes
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by artaxerxes »

never mind...
I understand how it works now....

just one question though:

the operation like cmpgt, sub etc... do they pop the 2 values they compare or do those values stay on the heap ?

thx

Artaxerxes
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Need help with usecode

Post by drcode »

There are no registers in this virtual machine; all operations work on the stack (kind of like the HP3000).

And yes, operations like cmpgt, sub, etc. pop the top two values off the stack, then push the result.
Locked