Web Rarely

Fudd's First Law of Opposition: Push something hard enough and it will fall over.

Reverse Engineering Dangerous Waters

2011-11-19

For a while I was playing the game Dangerous Waters by Sonalysts. It's a naval simulation game, and perhaps the most advanced of its kind, but it also has a number of annoying bugs and bits of bad coding. I tried to reverse engineer the game in hopes of eventually patching the executable to fix some of the bugs. I never got that far, but here's what I found.

Command Line Arguments

These are the command-line arguments that the game recognizes. The command line arguments can begin with either a slash (e.g. /n) or a dash (e.g. -n). The names of command-line arguments are case-sensitive.

Debugging

  • /debugoutput – Output debug information (requires an attached debugger).
  • /wences – Allows multiple instances of the game to run simultaneously, and uniquefies the names of replay files.

Graphics

  • /noswitchres – Disallow changes to screen resolution.
  • /no3d – Disables the 3D view.
  • /noenum – Do not try to enumerate display modes before running.
  • /adapterID <n> – Select the graphics adapter to use, where I believe 0 is the first, 1 is the second, etc, but I'm not sure.
  • /deviceID <n> – Select the graphics device to use, where I believe 0 is the first, 1 is the second, etc, but I'm not sure.
  • /modeID <n> – Select the graphics mode to use, where I believe 1 is the first, 2 is the second, etc, but I'm not sure.
  • /ATIFixed – Enables a graphics hack for ATI cards.
  • /wantManualClear – Enables a graphics hack for Geforce3 cards.
  • /wantVSync – Enable synchronization with the vertical retrace.
  • /limit – Repaints the screen at most once every 33 milliseconds.
  • /fullscreen – Start in fullscreen mode.
  • /windowed – Start in windowed mode.

Multiplayer

  • /host – Begin hosting a game.
  • /join <address> – Join a game at the given address.
  • /connect <address> – Same as /join.
  • /name <username> – Set the user name for multiplayer games.
  • /n <username> – Same as /name.
  • /maxplayers <n 1-30> – Sets the maximum number of players when hosting a game.
  • /gclaunched – Unsure. Forces the game to think that a multiplayer game has been launched on startup. Perhaps this is meant to be used by lobby software such as GameSpy?
  • /useiniseed – Use the seed from the INI file when generating a scenario.
  • /seed <n> – Use the provided seed when generating a scenario.
  • /scenario <name> – Sets the name of the scenario to use when hosting a game.
  • /hull <n 1-65534> – Sets the ID of the hull you wish to use.

UI

  • /lang <e|f|g|c|j> – Display text in English, French, German, Chinese, or Japanese (assuming the corresponding language pack is installed).
  • /skipopening – Skip the opening movies.
  • /nodisplay – Apparently unused.

Other

  • /nosound – Disable sound support.
  • /noreplay – Don't create a replay.
  • /noaggie – Unknown and possibly unused.
  • /noDDSSupport – Unknown and possibly unused.
  • /limitDDSTexSize – Unknown and possibly unused.
  • /? /help – Displays a help message.

Playing without the CD

To eliminate the need for the CD to be inserted while playing the game, simply do the following:

  1. Copy the "World" and "Music" directories from the CD to a location on the hard drive.
  2. Open HKEY_LOCAL_MACHINE\SOFTWARE\Sonalysts Combat Simulations\Dangerous Waters\1.0 in a registry editor.
  3. Edit cdInstallPath to the be the path to the parent of the "World" directory (e.g. if the "World" directory is at C:\DW\World, then set the value to C:\DW).
  4. Edit musicInstallPath to be the path to the "Music" directory (e.g. if the "Music" directory is at C:\DW\Audio\Music, then set the value to C:\DW\Audio\Music).

.ndx/.grp Archive File Format

The .ndx/.grp files hold nearly all of the game's assets. The file format is quite simple. The .grp file holds the data and the .ndx file holds indices into the .grp file.

.ndx Index File Format

An .ndx file contains a number of 100-byte records, each of which describes a single file stored within the .grp file. There is no header that tells the number of entries in the index; the file is simply a multiple of 100 bytes in length. The entries must be sorted case-insensitively by name, as the game uses strcmpi() and a binary search to find them. Names should also be unique within the index. Each index entry has the following format:

00h char name[80]          The nul-terminated name of the file within the archive, in ASCII
50h uint offset            The offset within the .grp file where the data starts
54h uint uncompressedSize  The uncompressed size of the data
58h uint compressedSize    The compressed size of the data (and its extent within the .grp file)
5Ch uint pixelWidth        If the file is an image, this is its width in pixels. Otherwise, 0.
60h uint pixelHeight       If the file is an image, this is its height in pixels. Otherwise, 0.

.grp Data File Format

A .grp file simply contains blocks of data at the offsets specified within the .ndx file. Each block of data is compressed with the PKWARE Data Compression Library compression format. This format is proprietary, but a (slightly erroneous) description of the format can be found in a Usenet post by Ben Rudiak-Gould on comp.compression. I have also implemented a compressor and decompressor in my IO library.

Archive Manager

I've implemented a pretty robust and full-featured archive manager for the .ndx/.grp archive format. It is released as part of my Dangerous Waters Mod Utilities package.

IDA Pro 6.1 Database

If you would like to continue my reverse engineering work, you can do so with IDA Pro 6.1 using my database file. This database was created to work with Dangerous Waters version 1.04 build 378. I recommend using the Hex-Rays decompiler.

Comments

Dangerous Waters 2012-08-21 08:03AM
Hi, excuse me for my bad English.
Congratulation for Your work !!!
I'm try to add new playable unit in DW, have Youn never work with weaponloadout ?It's very complicate to modify.

Best regards,
Fausto
an anonymous Fausto
RE: Dangerous Waters 2012-08-28 02:55PM
Hi Fausto,

I also looked into adding new playable units. I tried disassembling the DLLs used to implement the different stations. Unfortunately, the interface to the DLL is not simple, and it would require many months of reverse engineering to figure it all out, so I gave up on it. :-(

-- Adam
grp.exe 2012-09-03 11:29PM
Hello Adam,
I am starting to use your useful grp.exe to mod DW but unpacking a grp file I get the ERROR: There is insufficient space in the output buffer .
Can you please take a look to the possible bug and let me know how to workaround the error?
Thanks in advance for any help.
an anonymous Sertore
RE: grp.exe 2012-09-15 10:17AM
Yeah, I actually discovered that problem a few weeks ago, but I wasn't motivated to fix it. However, since you've asked, I'll look into it. I might already know the cause...
RE: grp.exe 2012-09-15 11:15AM
Okay, that problem is fixed.
2012-09-15 12:38PM
Hello Adam,
thanks for support: I will try the fixed grp in the next couple of days.

an anonymous Sertore
hi 2013-10-31 09:50AM
Amazing work you did. I was wondering if anyone had thought to take the 3d.ndx file from DW's Graphics folder and create higher resolution meshes and repaint the models to look more modern.
an anonymous Happyfeet
RE: hi 2013-11-05 10:55PM
Thanks. I guess I haven't actually done much here. There are a couple projects that change/improve the graphics (and many other things) in the game. The one I like best is called LWAMI. You can search for it, but here's a link what's currently the latest version: http://www.subsim.com/radioroom/downloads.php?do=file&id=3296
"Read" replay 2014-09-26 02:37PM
Hi, do You thing is possible to extract the position of units from a replay file ? Thank you
an anonymous Fausto
RE: "Read" replay 2014-10-09 08:30AM
Yes, it's possible, although you've left me no way to contact you. :-P
2014-10-14 05:11AM
Excuse me Adam ;-)
My intention is to try to get the last position of the units from the replay file as if it were a save file.

Thank You !!!
an anonymous Fausto
Editing dll 2017-01-21 12:27PM
I am wanting to help the RA team add more playable units any help I would be ever so greatfull
an anonymous Mr.Wood
AI Upscale 2023-04-22 06:41AM
I actually found this thread while attempting to AI upscale this game. I assume all the textures are in the 3d.ndx file?
an anonymous CamoFan

Add a comment

Note: The information you enter (including your name and email address) will be displayed publicly.




Line breaks are converted to <br>'s, and all HTML tags except b, u, i, tt, and pre are filtered out.