What IS the 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
Shanira

What IS the usecode?

Post by Shanira »

Hi,

I've been a long time watcher of Exult. I've used it a few times to rehash some experiences I've had with U7, and while having played U1-8 as well as UO, U8 is still my favourite.

Which lead me to watch the development of Pentagram. I've been waiting for a break a long time now, a rudimentary outline of information needed to do for U8 what Exult does for U7 (or at least get somewhere trying), and while I've downloaded all the documents and most of it seems straightforward enough, I do have a question, as I cannot simply use parts of your usecode handling code (I program in VB using C++ and occasonially ASM DLLs for the stuff that needs exceptional speed) and just generally since I haven't found any information is.

What IS the usecode?

As far as I can see, it's like a sort of crude DLL type thing mixed with the game script. Each NPC, egg (and object?) in the gameworld has a flex (I have no idea what that means either, just quotting you guys here ^_~) file, and when triggered the game engine looks up where the appropriate function is in the file, and then what? Use-Code, is this hard coded or a custom code script? If it's the latter, how would you go about deciphering it, or otherwise make it usable?

Well, enough rambling. Some help would be appreciated ^_^
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Colourless »

You may be waiting a while to see something out of pentagram. We are very much doing various experiments and also doing some level of design on pentagram before we really start to program it. We also want to be sure we have everything right before starting. Ultima 8's usecode is amazingly complex. Chances are if it's not interpreted correctly, the game will not be playable.

Well, at it's simplest USECODE is a scripting language that is used to control the game's plot. More technically it's a custom language that has been compiled into a bytecode that is interpreted by the game engine to control the game.

Almost all file formats in Ultima 8 are based on flexes. A Flex file just contains a bunch of other files that can be accessed by an index. The Usecode Flex in U8 contains a set of classes they get associated with each object in the game world. The class index in the Flex to use is the same as the Shape number of the object in the world.

Each class can contain multiple functions. Some of these functions have a specific purpose and are called by the game engine when certain events occur (i.e. doubled clicked).

To execute usecode you need an interpreter which is something that we (the Pentagram team) have been developing. The interpreter is in a sense a virtual CPU. Developing interpreter isn't the difficult part of the process though. The hard part is working out exactly what each opcode is meant to do, and what all the data passed to the opcodes do.

-Colourless Dragon
Darke
Site Admin
Posts: 173
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Darke »

Like Colourless said, USECODE is a bytecode language (like Java bytecode or
Pascal's p-code), which is a technically platform and architecture independent
language (although the only known interpreters exist for the i386 and above,
Dreamcast and Playstation *grin*). The code was originally written in a
usecode scripting language, then compiled down to binary code.

Each object may or may not have a chunk of code in one of the ?usecode.flx
files ('e'==English, 'f'==French, 'g'==German, and 'e'==Spanish for that
licensed version) that is either executed by an in game action (clicking or
double clicking on it, it leaving or appearing on the screen, etc.), or
executed by an internal usecode call (there appear to be classes written
solely for that purpose).

As far as we can tell so far, the usecode machine/interpreter is a
pre-emptively multithreaded stack machine, although we've not worked out which
opcodes change the state of the thread yet (put it into 'sleep' or let it
yield to the next thread in the chain, etc).

It also has an opcode that 'hooks' internal engine functions (like 'get me the
X value of this object' and 'generate me a random number between 1 and
value-on-stack', etc), of which we've got to emulate (all 182 of them), and it
also restricts us to trying to figure out how _their_ engine worked
internally, then emulating it precisely, because if we don't, we going to get
subtle errors in the usecode. Which is a Bad Thing, since it controls almost
everything (including most of the animations *grin*).

Almost all documentation of what we know about usecode is either in the files
disasm.cc (the disassembler), fold.cc (a kind-of working decompiler), and
UCMachine.cc (a minimally working interpreter), or in people's minds. *grin*
So your best bet is to either look there, or harass people (wjp, Colourless or
myself, Darke) on #exult, if you've got a specific question we may be able to
answer.

In the end, however, since usecode touches almost everything in the engine, I
suspect you'll be writing quite a bit of it in the C++ DLLs and almost
nothing in VB, unless you want to have VB calling C, then C calling your VB
program back continuously. Which is ok, but since usecode is the critical
path (all threads need to be executed once every 10th of a second or
something?), all the switching may cause a significant overhead to things.
(Although admittedly, I haven't programmed extensively in VB since VB 4, so
I've thankfully got no idea as to how it works. *grin* VB is not my favourite
language.)

Darke
(Hoping it's a somewhat coherent reply, since he just woke up. *grin*)
Shanira

Re: What IS the usecode?

Post by Shanira »

Well, the main reason I use VB is because it spares me a lot of grief and pain learning the MFC and how to use DirectX from VC++ (I just can't stand the MFC, that kinda hampers your learning ability). In VB I can get a graphical system set up in +/- 3 minutes, in VC++, well, frankly, I just wouldn't know where to start, it's never interested me and the overwhelming amount of compiler (windows) specific stuff you need to get a VC++ project running properly in a window is just way too annoying for me to handle. I'm used to having a Main function, and working from there ^_~

I see the Usecode is a bit more extensive than I thought, if it controls clicks on items, animations, plot, then basically unless I'm wrong the actual coding for someone to do is make something to interact with it in the right way. Seems like I'm way in over my head here, but you're right, the VB+C++DLLs approach probably isn't going to fly.

I'll have to take a dive into the Exult (and pentagram?) source and see if I can make a bit more sence of things, since stuff like this is pretty new to me. (actually, to be more specific, completely new ^^;)
Darke
Site Admin
Posts: 173
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Darke »

(MFC) I don't like it either. *grin* The reason I code crossplatform under
Unix based OSes nowdays is completely coincidental. Really!

Usecode certainly has it's tentacles firmly embedded in almost every aspect of
the engine. (Click on an item to get a little bit of descriptive text popping
up? That's usecode creating a new text gump, which then sleeps the current
usecode thread for 3 seconds or something, whilst all other threads continue
to run, then 'unsleeps' it when the gump times out and the thread cleans up
after itself and terminates. Elegant? Yep. 'Interesting' to replicate? Most
certainly. *grin*)

There's a nine part tutorial here about writing a scripting language that
'might' help if you've never encountered one before, no idea how useful it
might be though: http://www.flipcode.com/tutorials/

If you're grabbing the code from cvs, make sure you get it from the 'old'
module in the pentagram cvs (docs are in the 'pentagram' module), rather then
the 'pentagram' module in the exult cvs, which has a note in the ChangeLog to
say it's depreciated. *grin*

Good luck with understanding things. *grin*

Darke
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Colourless »

Darke actually made a mistake in one of his posts. He says U8's usecode is pre-emptive, when it's actually co-operatively multithreaded.

Also you will want to get the up to date pentagram sources from the Pentagram Project CVS repository, not the Pentagram module in the Exult CVS repository. Here's a link to the Pentagram CVS repository: http://sourceforge.net/cvs/?group_id=53819

-Colourless Dragon
Armchair_Avatar

Re: What IS the usecode?

Post by Armchair_Avatar »

I'm curious: is Ultima 8's Usecode more flexible/advanced than Ultima 7's Usecode?

And BTW, since the Ultima 8 source code still exists, we could petition EA to release it (which would save you a lot of work, unless you're reverse-engineering U8 for recreational purposes ;-)
I know that EA will probably just ignore this kind of petition, but I guess it doesn't hurt to try.
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Colourless »

Yep, Ultima 8's usecode is more flexible and advanced than Ultima 7's. There are a number of reasons for this, but mostly because it's Multithreaded and Object Orientated. The compiled bytecode is also cleaner and tends to be more logical than Ultima 7's was. In general Ultima 8's engine is a fair amount more sophisticated than Ultima 7's.

EA releasing the source is extremely unlikely since various parts of the engine used licensed code. Even if they did release the source, it's usefulness will be somewhat limited to educational purposes only. This is because the original programmers did a number of gross hacks in various parts of the engine that make it almost impossible to port.

You can argue that we are doing Pentagram because we can. We have the knowledge, we have the skills, so why not.

-Colourless Dragon
Kuroshi
Posts: 67
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Kuroshi »

Gentlemen, we can rebuild him. We have the technology. We have the capability to make the world's first bionic man. Steve Austin will be that man. Better than he was before. Better ... stronger ... faster.
Armchair_Avatar

Re: What IS the usecode?

Post by Armchair_Avatar »

Where is that quote from?
Kuroshi
Posts: 67
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Kuroshi »

The Six Million Dollar Man.
Darke
Site Admin
Posts: 173
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Darke »

Well it was calculated that it would have cost $3 million to produce
exult, so $6 million for pentagram is probably not _that_ far off. *grin*

Darke
(Who thinks we need to get a theme tune and start writing scripts.)
Pertex

Re: What IS the usecode?

Post by Pertex »

you always talk about usecode of U8 but Exult is for U7. Does this mean, that the exultteam wants to implement the syntax of U8-usecode in Exult?
Dominus
Site Admin
Posts: 5656
Joined: Thu May 14, 2020 1:34 pm

Re: What IS the usecode?

Post by Dominus »

No. Part of the team is working on Pentagram - a program that is intended to play the U8 data files. For now there is already a snapshot of the Pentagram tools availlable that gives you a map viewer, a shapes viewer, an animation viewer and some other programs.
Pentagram itself has not yet been started.
For Pentagram to work ebventually the usecode of U8 needs to be understood. U8 usecode-style will not be implemented in Exult...

Edit: Froze thread as it seemed to attract spam!
--
Read the documentation and the FAQ! There is no excuse for not reading them! RTFM
Read the Rules!
We do not support Piracy/Abandonware/Warez!
Locked