TAC Files and LZSS

Terrain / Theater editing

Moderators: Lone Wolf, Snake Man

Post Reply
tiag
Newbie
Posts: 5
Joined: 2011-07-31 21:10:48
Gaming Interests: Falcon 4.0
Editing Interests: Modeling

TAC Files and LZSS

Post by tiag » 2011-07-31 22:04:57

Hi Guys,

First time here but an old Falcon3/4 addicted. I have been modding Falcon AF and OF for my own use for a while, but now decided to attack the old problem of the TAC/CAM files.

Thats my problem:

I wrote a small prog to read the the TAC files and am getting all files embedded (and its sizes) it should have. I can parse everything according to your wiki (which is great btw), but I am struggling with the LZSS. Unfortunately I cannot use the wikis code to decompress the compressed part of the files (because I am using another language), so I wrote LZSS by myself last week. It works with other example files I have, but it is not working with F4 files. I already "abused" the search of the forum and could not find anything that could help me on that. The most interesting stuff is from a guy named Lightining (still round?):
viewtopic.php?f=12&t=21775

From the old Falcon 4 leaked code, the LZSS works with 12bits for the index and 4bits for the length and according to the wikis code, it seems to be still the case. But how is this 12+4 bits information stored for compressed data? And about the flag bit: How it is saved? Have been trying a lot of possibilities but w/o any success.

Would really appreciate any help.

Tiag
555th VFS

WlodekG
Recruit
Posts: 29
Joined: 2011-06-20 13:38:41
Gaming Interests: Falcon 4.0
Editing Interests: Missions

Re: TAC Files and LZSS

Post by WlodekG » 2011-08-01 11:25:07

Hi. This is the procedure I use to decompress, and I hope that will be useful for you
(my editor I wrote in C++).

Code: Select all

#define then
#define WINLEN            0x1000

byte    SlideWin[WINLEN+19];

/****************************************************************************/
/*+------------------------------------------------------------------------+*/
/*| Function: ExpandLZSS -                                                 |*/
/*| Purpose : Decompress LZSS                                              |*/
/*+------------------------------------------------------------------------+*/
ulong ExpandLZSS(const byte * inpBuf,ulong inpLen,byte * OutBuf,ulong outLen)
{
  byte * s = SlideWin;
  byte * q = SlideWin + WINLEN;

  ulong Fl = 0;
  ulong pi = 0;

  //**************************************************
  // Decompression loop
  //**************************************************
  while((outLen > 0) && (pi < inpLen))
   {
    byte Flag = inpBuf[pi++];

    //**************************************************
    // up to 8 bytes of data or 8 pointers or
    //**************************************************
    for (byte bits=0; bits < 8; bits++, Flag >>= 1)
     {
      if (pi >= inpLen) then return Fl;
      if (Flag & 0x01)               // raw data
       then
        {
         *s++ = OutBuf[Fl++] = inpBuf[pi++];
         if (s >= q) then s = SlideWin;
         if (!--outLen   ) then return Fl;
         if (pi >= inpLen) then return Fl;
         continue;
        }

      ASSERT((pi + 2) <= inpLen); 

      byte a = inpBuf[pi++];
      byte b = inpBuf[pi++];
      ulong u = (a << 8) | b;

      byte  rlen = byte(u >> 12) + 2;
      ulong Rpos = (u & 0x0FFF) - 1;
      ASSERT(Rpos < WINLEN);

      byte * src = &SlideWin[Rpos];
      byte * dst = &OutBuf[Fl];
      Fl   += rlen;
      while (rlen--)
       {
        ASSERT(src <= q); 
        if (src == q) then src = SlideWin;
        *s++ = *dst++ = *src++;
        if (s >= q) then s = SlideWin;
        if (!--outLen) then return Fl;
       }
     }
   }
  return Fl;
}
Good luck.

tiag
Newbie
Posts: 5
Joined: 2011-07-31 21:10:48
Gaming Interests: Falcon 4.0
Editing Interests: Modeling

Re: TAC Files and LZSS

Post by tiag » 2011-08-01 11:34:54

Thank you very much. Will take a look this evening at home.

Cheers!

Tiag

tiag
Newbie
Posts: 5
Joined: 2011-07-31 21:10:48
Gaming Interests: Falcon 4.0
Editing Interests: Modeling

Re: TAC Files and LZSS

Post by tiag » 2011-08-02 11:40:10

Well, Wlodgek, it seems I am doing the expansion using the correct bits 4+4+8 as you do, but it is still not working. I also tried with bitshifts as you did, but no joy.

One thing I could not understand, where the "19" on the definition of SlideWin comes from?! May be my mistake is there....have to think about.

Tiag
555th VFS

WlodekG
Recruit
Posts: 29
Joined: 2011-06-20 13:38:41
Gaming Interests: Falcon 4.0
Editing Interests: Missions

Re: TAC Files and LZSS

Post by WlodekG » 2011-08-02 12:00:39

Hi tiag.

First, please write in what language you write your program.

19 = (1 << 4) + 2 + one byte (probably for safe :? )

I have to confess that this algorithm was taken from the network (but can't remember where) and some matched to my needs.

The algorithm itself is very simple and should work without any problems. More difficult is the procedure for compression (because of speed).

tiag
Newbie
Posts: 5
Joined: 2011-07-31 21:10:48
Gaming Interests: Falcon 4.0
Editing Interests: Modeling

Re: TAC Files and LZSS

Post by tiag » 2011-08-02 13:53:49

I am writing everything in LabView because I want to save time with the graphic interface later. I decided to "jump" the LZSS expansion and I write the whole parsing for a non-compressed dataset for all files (according to the wiki).

But now I have to deal with the LZSS....this 19 is eventually an issue I did not think about.

What I think really strange (and is definitely wrong) in my prog is that I get index values (yours Rpos) for compressed which are well over the size of the compressed file.
Am I right? For compressed data, you have 2 bytes: First four bits of the first byte are the high four bits of the 12 bits Rpos? The second four bits of the first byte are the length? And the second byte are the low 8 bits of the Rpos?

I will probably have to write a DLL with your code and call it in LabView. :cry:

I will post later some photos of my LabView code, maybe you can figure out what is wrong.

tiag
555th VFS

WlodekG
Recruit
Posts: 29
Joined: 2011-06-20 13:38:41
Gaming Interests: Falcon 4.0
Editing Interests: Missions

Re: TAC Files and LZSS

Post by WlodekG » 2011-08-02 14:22:38

Am I right? For compressed data, you have 2 bytes: First four bits of the first byte are the high four bits of the 12 bits Rpos? The second four bits of the first byte are the length? And the second byte are the low 8 bits of the Rpos?
No - it is bad.

First four bits (upper four bits) of the first byte are the length. To this number you must add 2.

Second four bits (lower four bits) of the first byte are the for example x;
Next whole byte is for example y; Then:

Rpos = x * 256 + y; (it is simple :D )

My old programmer's good advice - do not use numbers (variables) with a sign anywhere - never! (unless it is absolutely, absolutely, absolutely necessary.) Of course this does not concern the number of float point.

I hope this will help you.

tiag
Newbie
Posts: 5
Joined: 2011-07-31 21:10:48
Gaming Interests: Falcon 4.0
Editing Interests: Modeling

Re: TAC Files and LZSS

Post by tiag » 2011-08-04 07:45:33

Sorry, that is exactly what I meant. I am doing the same thing. Will go in vacations tomorrow when I come back will take a look into it again.

Thanks anyway, WlodekG.

Tiag

Post Reply

Return to “Terrain / Theater”

Who is online

Users browsing this forum: No registered users and 2 guests