Thursday, December 26, 2013

Recovering the lost "sys: cmnd" documentation

One of the aspects of the CAOS specification I got exited about when I first saw it mentioned in the C1 CAOS guide was the "sys: cmnd" command.
Quoting from the manual :

  SYS: menu commands 

CMND id# - issue an ID_XXX command message to the application. This
 allows macros to activate ANY menu command. Note that command
 will get executed LATER - fn doesn't wait before returning!
  id# is the decimal ID_XXX value - look these up in the resource
 file & list them for users

This sounds awesome ! The ability from our external application (or COBs) to execute any existing game command!
This will greatly help us, allowing us to add pause/play buttons to our custom applications, to run existing applets, export and import Norns...

All right, let's head to the mentioned "resource file" and try this command !
Err...yes...the ummm...resource file... Which one ?
Well...none it seems...

After extensive browsing searching and such, I could not find any single online reference to those ID's for the Creatures 1 game...
This awesome set of possibilities was forever lost, probably because the developer in charge never took the time to "list them for users".

 The only thing I was able to come up with from the highly buggy CDN site was a list of usable ID's that seemed written for the C2 game.

I tried some of these, which surprisingly enough worked, but most of them didn't.
That was a first step, but many of the most interesting features were still out of reach.

( To run CAOS commands directly inside C1 I suggest you refer to the awesome Creatures developer ressource site on how to write custom applications for the Creatures series, or directly use it's author's CreaturesCommander tool from his utilities pages )
This might also be the right time to mention that despite not being mentioned anywhere, the C2 engine has the exact same DDE interface for communicating with third party apps as C1 does.This means the utility also works with no adaptation on C2.
A CAOS console is also available in the Genetics Kit.

Running "sys: cmnd 32771" against C2 engine with the CCmdLine tool, toggles the "view" window as mentioned in the CDN document

So what do we do ?
My first thought was " well, let's reverse engineer the game, find the CAOS interpreter, locate the 'sys: cmnd' handling part of the engine, and look for some kind of lookup table".We could then list those ID's right at the source.
That would sure do the trick, but there's a lot more in the game that would require such a level of involvement. No need to make our life more miserable than it needs to be just yet. Maybe there's an easier way ?

The documentation mentions "activate ANY menu command" and also a "resource file".

Well, sure enough, this might look familiar to a windows developer.What if those ID's were somehow correlated to the actual menu items from the window manager ? Maybe those would be an easier target ?
Checking it out shouldn't hurt.

So, let's grab a copy of "reshack", the resource hacker.
As it's name suggests, reshack a tool used to edit part of compiled executables containing it's various resources : icons, dialogs and of course menus.

This tools allows us to browse any binary, and list or change some of the information from it's resources section.
By firing the tool, opening the Creatures 1 main executable from the menu and navigating to through the "Menu" treeview, what do we find ?

A listing of all menu items form the game, along with some kind of numbers.
Don't these look familiar ?

Many of them match the Creatures 2 working ID's we've just tested.That looks promising !
By further trying to execute the "sys: cmnd XXX" command with those values, we can confirm that all of these now work !

We now have the full listing for the long lost "sys: cmnd"command :)
From now on, we can access all game actions from insde our third party tools, such as running applets, pausing the game, or importing and exporting Norns.

But wait! There's much more!
Some of the commands listed in there don't belong to the game menus we know of. We've just discovered the first of the many game secrets we will be discussing! Secret menu items with VERY interesting options !
(well, actually many of them match the ones available through the various games "cheats", but still an intersting find ;)

But let's talk about those in full detail in the next article.

Meanwhile, if all you need is the complete sys:cmnd ID list, you can find it here.

No comments:

Post a Comment