Author Topic: Some Logics have blank messages?  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

Offline cosmicr

Some Logics have blank messages?
« on: April 10, 2022, 06:47:32 PM »
I wrote a logic decompiler! Pretty pleased with it - it's working great.

I've been testing it on a few Sierra titles, but noticed along the way that some games (eg Gold Rush logic 42) have blank messges? Is this some hangover from their compiler? It took me ages to work out what was wrong with my decompiler.

At the end of the code section there's a list of offsets/pointers to messages, which in this example there are 134 pointers. But when you get to the actual messages about 30 are blank? Anyone know why this is?

Messages are split by zero '\0' bytes, when you get to the blank ones, they're literally just nothing followed by a zero byte. How should an interpreter handle these?

I'm thinking that the original source code must have used the message numbers (rather than compiling them into a list later) and as they went along and made edits, they just added new messages instead of reordering their list?



Offline Collector

Re: Some Logics have blank messages?
« Reply #1 on: April 10, 2022, 08:07:52 PM »
I would love to get an AGI decompilation archive like Eric Oakford's SCI archive. I know he has started one for AGI, too, but this could help. You could look at the LSL1 original source that was released and compare your result against it. It is missing the system logics. https://github.com/historicalsource/leisuresuitlarry
KQII Remake Pic

Offline cosmicr

Re: Some Logics have blank messages?
« Reply #2 on: April 10, 2022, 11:59:39 PM »
Ah I see! Perfect I didn't realise this existed. Thankyou for this.

It does appear that they use a separate file for messages, and use the references only. So it is very likely that as the game develops messages get removed whilst new ones are added at the end. :) Also interesting to see they don't use the new room command - they just set a variable that must be checked on each cycle or something.

A decompilation archive would be good. My decompiler only creates a list of commands (kinda like an AST) and prints them out.  I'm not really developing anything, just having a bit of fun. It doesn't follow any conventions. I see WinAGI's format uses a similar convention to the LSL1 source, albeit slightly different. AGI Studio is completely different again.

Is there an accepted convention for AGI code format?
« Last Edit: April 11, 2022, 12:05:06 AM by cosmicr »

Offline AGKorson

Re: Some Logics have blank messages?
« Reply #3 on: April 11, 2022, 01:44:55 AM »
Or you could look at the full decompilation of Gold Rush that I posted in this thread.

Logic 42 in GR (rm.SternShipInterior) does have messages that go up to #134. But several of them (42, 47, 48, 53, 56, 67, 73-76, 87, 96-112, 121, 132) have invalid pointers. Specifically, they have an offset value of zero.

This happens a lot in Sierra logics. It's a result of how their original compiler handles messages that are not defined when a logic was compiled.

The message section of a logic is formatted as follows (where X is offset to last byte of command data):
Code: [Select]
offset(bytes)       data
X+1           | highest index of messages in the logic
X+2, X+3      | word offset to last byte of actual text data (measured from start of message section, X+1)
X+4 - X+4+Z   | message text offset table, equals highest index value times 2 (i.e. two bytes per message)
                Z = (highest message index * 2) - 1
X+4+Z+1 - EOR | message text, encrypted with 'Avis Durgan'

The values in the offset table are relative to the location of the offset to last byte of actual text data, i.e. X+2. What this means is to calculate the start of a message, you add the value from the offset table to X+2.

For logic 42 in GR, X = 4671, so the message section starts at 4672. The reference point for calculating offsets (and pointer to end of text data) is at 4673. The message text offset table starts at 4675 and runs through 4942 (268 bytes for 134 messages). The text data starts at 4943.

The offset values for the invalid messages listed above are all zero. Which means if you tried to use them in a logic, they would point to 4673 (X+2). This is because when Sierra's compiler (CG.EXE) creates a logic, it defaults to a value of zero for message text offsets, and only updates it if a message was assigned in source code using the #message command.

Note that if a null string was assigned, the compiler would add a zero length string (a single \x00 byte), and adjust the message table offset value accordingly. So invalid messages are not the same as null messages.

Also, the interpreter actually checks for cases where a logic tries to access a message that hasn't been defined; if the offset of a message passed in a command is zero, AGI will raise trappable error 14 (the WinAGI Help file contains a detailed description of that error code). So you can't access an undefined message. This is one of the rare instances where AGI actually validates data used in AGI commands.


While original Sierra source files do use a separate, included file for messages, it was not required. But unlike modern compilers, messages could only be referenced in commands by their number, i.e. 'm1', 'm2'; you couldn't compile messages in line (i.e. this would NOT compile in CG.EXE):
Code: [Select]
print("sample message");
The original AGI specs describe a convention for AGI source syntax that AGI Studio and WinAGI both conform to.( I also added additional features to WinAGI that aren't in AGI Studio - if interested, see the WinAGI help file or ask me for details.)

The syntax rules for original Sierra compiler can be found in the agiwiki, or in this post. They are derived from a full disassembly of CG.EXE. There are several significant differences between original Sierra syntax rules and what the AGI Specs consider 'canon'. But since the specs have been around for so long, and most non-Sierra compilers are based on the AGI Specs, there doesn't seem to be much reason to change. I am considering adding a 'CG.EXE compatible' mode to WinAGI at some point just for nostalgia, which would allow it to compile original Sierra source with no modifications. But it would only be for nostalgia, and wouldn't be of much practical use.
« Last Edit: July 26, 2022, 10:08:31 AM by AGKorson »

Offline cosmicr

Re: Some Logics have blank messages?
« Reply #4 on: April 11, 2022, 02:39:55 AM »
Pretty much as I had deduced - thanks for the confirmation!

I see there must have been a few revisions of the WinAGI style code format.

My old project from years ago doesn't seem to work anymore:



This is on a comment using the ' character. I'm guessing it's not backwards compatible?

Offline AGKorson

Re: Some Logics have blank messages?
« Reply #5 on: April 11, 2022, 10:44:48 AM »
Yeah, the only valid comment markers are '[' and '//'

The single quote comment marker was only allowed in VB syntax (which was removed a couple years ago).  I don't recall ever supporting it for the 'normal' AGI syntax. If I did, it was by accident.

The only thing that I removed from the syntax rules was support for block comments '/*  ... */'. If you have those in your code, you will need to replace them with a comment at the start of each line. The Block Comment feature in the text editor will handle that for you easily.

« Last Edit: April 11, 2022, 11:32:43 AM by AGKorson »


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.064 seconds with 30 queries.