Author Topic: Hacking and rebuilding DAX-files  (Read 2922 times)

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Hacking and rebuilding DAX-files
« on: October 03, 2015, 09:07:37 AM »
I experimented with some DAX-file hacking:




Pool of Radiance. Vala has fallen and joined Tyranthraxus. Note the party character combat icons (colors are not 100% correct) and the modified game font.




Tyranthraxus has its stats changed and the icon updated to a more modern one.




Secret of the Silver Blades. I removed the storm giants and clerics from the final combat (changed their enabled status from 1 to 0). Dreadlord and Lord Soth have combined their forces and are stronger than ever. I gave the lich access to Delayed Blast Fireball and he being the old gent he is, he politely asks the player when it would be an appropriate time for the fireball to explode (yeah, I didn't remember that DBF works this way in Secret).








The newest Gold Box Companion has 3 very experimental mod-tools included: Font-, Icon- and Monster-modder. Only works with DAX-files and only EGA-icons are supported. The icon hack works so-so, I don't yet completely understand what the EGA-palette entries in the icon files are so I just use a default palette. Also the character's icon colors affect the icons. If the mods happen to trash a DAX-file there's a restore-button that restores the original one.

http://personal.inet.fi/koti/jhirvonen/gbc/gbc.zip

« Last Edit: October 03, 2015, 10:21:57 AM by jhirvonen »

Offline hans

  • Hero Member
  • *****
  • Posts: 2697
Re: Hacking and rebuilding DAX-files
« Reply #1 on: October 03, 2015, 10:16:43 AM »
WOW!!! 
 
:icon_cyclops_ani:

Offline steve_mcdee

  • Dungeon Craft Tester
  • Hero Member
  • ***
  • Posts: 1949
Re: Hacking and rebuilding DAX-files
« Reply #2 on: October 03, 2015, 03:03:40 PM »
I gave the lich access to Delayed Blast Fireball and he being the old gent he is, he politely asks the player when it would be an appropriate time for the fireball to explode (yeah, I didn't remember that DBF works this way in Secret).
Haha. The designers' desire to allow enemies who can cast delayed blast fireball might perhaps explain why the "delay segments" approach was not used in other gold box games then.

Great work!

Offline marainein

  • Sr. Member
  • ****
  • Posts: 372
Re: Hacking and rebuilding DAX-files
« Reply #3 on: October 03, 2015, 10:16:06 PM »
Ace work! I wanted to get this into gold box explorer 1.3, but you've beaten me to it. Did you write a repacker for the dax format? Does it produce identical byte output when recompressing unchanged contents of a dax file?

Offline Ishad Nha

  • Hero Member
  • *****
  • Posts: 943
Re: Hacking and rebuilding DAX-files
« Reply #4 on: October 03, 2015, 11:49:52 PM »
There has been interest in a DragonLance Unlimited Adventures, a DragonLance version of FRUA. With decryption as good as you are doing that might be possible.

Rare events, check for Race or Class and so on. If you have not found them yet you will need to look in Gold Box games to see where they occur.
Check for Class occurs in Champions of Krynn (Tomb of Sir Dargaard) and Dark Queen of Krynn (looking for a Thief to unlock the grate in the Dragon area of the Tower of Flame, also looking for someone to command the rune in the same place?) Then there are the segregated training halls of Phlan in Pool of Radiance.
Check for Race, occurs in the Draconian Caves of DQK, early in there is a discussion of Dwarven Spirits.
« Last Edit: October 03, 2015, 11:54:46 PM by Ishad Nha »

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Re: Hacking and rebuilding DAX-files
« Reply #5 on: October 04, 2015, 10:41:41 AM »
Did you write a repacker for the dax format? Does it produce identical byte output when recompressing unchanged contents of a dax file?

Yes, most work was already done by Simeon years ago by figuring out the RLE of the DAX-files, so it was easy enough to write the repacker.

It's mostly byte perfect when a rewritten unchanged file is compared to a original one but I just noticed some differences when writing a unchanged Pools of Darkness monster-dax.

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Re: Hacking and rebuilding DAX-files
« Reply #6 on: October 10, 2015, 07:11:47 PM »
Fixed a bug in DAX rebuilder routine (hopefully it's now byte perfect if no changes are made) and added a tool to modify items:







In the screenshot examples, I added 2 items to ITEM3.DAX, record 53, which is the general store inventory in Phlan civilized district. I added a bigger bundle (250) of arrows and a Sling of Tempus which is a Fine Sling (Strength-bonus to damage, usable by all classes). The Fine Sling required editing the item properties file.

Offline Simeon Pilgrim

  • Full Member
  • ***
  • Posts: 167
    • simeonpilgrim.com
Re: Hacking and rebuilding DAX-files
« Reply #7 on: October 10, 2015, 10:45:26 PM »
Fixed a bug in DAX rebuilder routine (hopefully it's now byte perfect if no changes are made) and added a tool to modify items:

out of interest, was the bug on the encode or decode stage..

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Re: Hacking and rebuilding DAX-files
« Reply #8 on: October 11, 2015, 02:17:00 AM »
Fixed a bug in DAX rebuilder routine (hopefully it's now byte perfect if no changes are made) and added a tool to modify items:

out of interest, was the bug on the encode or decode stage..
encode

Offline marainein

  • Sr. Member
  • ****
  • Posts: 372
Re: Hacking and rebuilding DAX-files
« Reply #9 on: October 11, 2015, 05:59:09 AM »
So you've effectively reversed the compression algorithm SSI used. How does it decide when to do run length compression and when not to?

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Re: Hacking and rebuilding DAX-files
« Reply #10 on: October 11, 2015, 07:39:41 AM »
So you've effectively reversed the compression algorithm SSI used. How does it decide when to do run length compression and when not to?

Simeon described the format:
Quote
The file start with a 2 byte data_offset, then there are N ( (data_offset -2) / 9 ) header elements.

Each header element is 9 bytes long and consist of:
struct header

  UBYTE   id;
  UINT    offset;
  UWORD   raw_size;
  UWORD   stored_size;

The data for each block is located in the file at data_offset + header.offset. header.stored_size bytes are read then decompressed into header.raw_size bytes.
Data Decompression

Data blocks are compressed using a simple RLE scheme. The first byte (signed) is read, if greater/equal to 0 that many bytes +1 are copied to the output.
Otherwise (when less than zero) the next byte is copied to the output for the negative first byte count.

Encoding:

- for each data block in a DAX file:
  - loop until whole block is encoded
    - get count of sequential identical bytes (I've set the max count to 127)
    - get count of sequential bytes where the next byte differs from the previous one (I've set the max count to 126)
    - depending on which count is higher, store the control byte + byte to be copied / array of bytes depending on the case
    - increase offset by count
  - update the header for this data block with raw size, stored size and data start offset

create the file:
- data offset (2 bytes)
- headers (9 bytes each)
- data

This can lead to situations where stored data size can be bigger than raw data size, also on original SSI's files. Check out Pools of Darkness item0.dax, raw data size 4318 bytes vs stored data size 4567 bytes.

Offline Null Null

  • Maker of excessively difficult vanilla mods
  • Hero Member
  • *****
  • Posts: 565
Re: Hacking and rebuilding DAX-files
« Reply #11 on: October 11, 2015, 06:40:51 PM »
I salute you, sir. Amazing stuff.

Is there a way to save your changes? I wonder if people could release 'remakes' of these games where, for example, the ruins of Old Phlan are inhabited by the Cult of Moander rather than goblins and orcs, and Tyranthraxus is a beholder.

I always thought FRUA had an underused capacity for the bizarre...

OK, downloaded it. For some reason when I load it, my list of games is blank...I tried moving it to a subdirectory in root...
« Last Edit: October 11, 2015, 09:57:22 PM by Null Null »

Offline jhirvonen

  • Jr. Member
  • **
  • Posts: 92
Re: Hacking and rebuilding DAX-files
« Reply #12 on: October 11, 2015, 10:08:10 PM »
Is there a way to save your changes? I wonder if people could release 'remakes' of these games where, for example, the ruins of Old Phlan are inhabited by the Cult of Moander rather than goblins and orcs, and Tyranthraxus is a beholder.
Changes are made directly to the DAX files and there is no logging of made changes. I guess you could use some diff/patch utilities and scripts to make installable mods without actually distributing the DAX files.

 

Offline Null Null

  • Maker of excessively difficult vanilla mods
  • Hero Member
  • *****
  • Posts: 565
Re: Hacking and rebuilding DAX-files
« Reply #13 on: October 12, 2015, 06:43:02 PM »
OK. Any idea why the list of games is blank? I would like to start playing with this thing!

Offline Ishad Nha

  • Hero Member
  • *****
  • Posts: 943
Re: Hacking and rebuilding DAX-files
« Reply #14 on: October 12, 2015, 09:10:02 PM »
I have all Gold Box games and the Gold Box Companion in the same directory.