.imb/.pal files - Railroad Tycoon II

Textures, recreate headers, conversions, algorithms and parsing of image files
Bwolna
Posts: 15
Joined: Fri Jun 10, 2022 3:09 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by Bwolna »

How to run jar file from command prompt: https://stackoverflow.com/questions/577 ... and-prompt
You have to install java: https://www.java.com/en/

Program will extract all sprites that it understands:

Code: Select all

Extract sprites from BL1CMINE.IMB
Number of sprites: 1
sprite #00
  sprite type 3
  Use palette PALT0282.PAL
  Number of blocks: 2
    block #00_00
    number of images: 7
      image #00_00_00
        image dimensions: 164x185
        packed size: 13006, unpacked size: 30340
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_00.unpacked"
      image #00_00_01
        image dimensions: 13x32
        packed size: 85, unpacked size: 416
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_01.unpacked"
      image #00_00_02
        image dimensions: 13x32
        packed size: 82, unpacked size: 416
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_02.unpacked"
      image #00_00_03
        image dimensions: 17x37
        packed size: 94, unpacked size: 629
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_03.unpacked"
      image #00_00_04
        image dimensions: 20x15
        packed size: 78, unpacked size: 300
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_04.unpacked"
      image #00_00_05
        image dimensions: 21x35
        packed size: 131, unpacked size: 735
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_05.unpacked"
      image #00_00_06
        image dimensions: 21x39
        packed size: 148, unpacked size: 819
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_06.unpacked"
    block #00_01
    number of images: 7
      image #00_01_00
        image dimensions: 136x114
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
      image #00_01_01
        image dimensions: 4x4
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
      image #00_01_02
        image dimensions: 4x4
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
      image #00_01_03
        image dimensions: 4x4
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
      image #00_01_04
        image dimensions: 3x3
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
      image #00_01_05
        image dimensions: 1x1
        packed size: 2, unpacked size: 1
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_01_05.unpacked"
      image #00_01_06
        image dimensions: 1x1
        packed size: 2, unpacked size: 1
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_01_06.unpacked"
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

Thanks, I can extract the files fine using that, but how do I get GBS to open the extracted files?
Bwolna
Posts: 15
Joined: Fri Jun 10, 2022 3:09 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by Bwolna »

Extract image, copy logs to some text file (to use it later):

Code: Select all

image #00_00_00
        image dimensions: 164x185
        packed size: 13006, unpacked size: 30340
        saved "/test/RR2/BL1CMINE.IMB.sprites/00_00_00.unpacked"


In GBS:
File -> Load file -> BL1CMINE.IMB.sprites/00_00_00.unpacked
Set width and height to 164 and 185
select "Grey #1" palette from drop-down list of built-in palettes.
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

Great, I take it you haven't figured out how the palettes work yet?
Bwolna
Posts: 15
Joined: Fri Jun 10, 2022 3:09 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by Bwolna »

Something like this:

Code: Select all

      Path sourceFile = Paths.get("/home/owner/test/RR2/PALT0504.PAL");
      byte[] rawFile = Files.readAllBytes(sourceFile);
      int count = readLong(rawFile, 0);
      for (int i=0; i<count; i++) {
         byte[] pal = new byte[768];
         for (int j=0; j<256; j++) {
            int color = readWord(rawFile, 4+ 0x23 + i*512 + j*2);
            int c1 = color & 0x1F;
            int c2 = (color >>> 5) & 0x1F;
            int c3 = (color >>> 0xA) & 0x1F;
            pal[j*3 + 0] = (byte) (c1 << 2);
            pal[j*3 + 1] = (byte) (c2 << 2);
            pal[j*3 + 2] = (byte) (c3 << 2);
         }
         Path newFile = Paths.get(sourceFile.toString() + "." + i + ".pal");
         Files.write(newFile, pal,
               StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
      }
   }
}

If you know what picture could be used to find which of colors is red-green-blue, write here.
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

Here's BL1SHEEP.IMB in-game. Is this the sort of thing you're looking for?
rrt2sheepfarm.png
Bwolna
Posts: 15
Joined: Fri Jun 10, 2022 3:09 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by Bwolna »

Code: Select all

Extract sprites from BL1SHEEP.IMB
Number of sprites: 1
sprite #00
  sprite type 3
  Use palette PALT0239.PAL
  ...


Code: Select all

Convert palettes from PALT0239.PAL
Number of palettes: 4
palette #00
  saved "/home/owner/test/RR2/2/PALT0239.PAL.palettes/00.pal"
palette #01
  saved "/home/owner/test/RR2/2/PALT0239.PAL.palettes/01.pal"
palette #02
  saved "/home/owner/test/RR2/2/PALT0239.PAL.palettes/02.pal"
palette #03
  saved "/home/owner/test/RR2/2/PALT0239.PAL.palettes/03.pal"


I don't how the game chooses one from these four palettes, but when I selected "00.pal" in GBS the image looks similar to your example. For other files you should try all extracted palettes to choose best match.
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

That seems to work well, thanks a lot. I think the different palettes are for when you build buildings in the game. I'll let you know if I encounter any other problems.

Edit: My only comment is that it would be nice if you could support whatever 0x20 is.
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

I'm not sure if this helps, but I'm fairly certain the sprites that produce the "unpacking !0x20 not implemented" error are the ones with transparency.
Bwolna
Posts: 15
Joined: Fri Jun 10, 2022 3:09 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by Bwolna »

eldomtom2 wrote:but I'm fairly certain the sprites that produce the "unpacking !0x20 not implemented" error are the ones with transparency.


Added !0x20 and 0x20 branches to sprite extractor tool.

Sprites with 0x20 are not used when game works in 16-bit mode, and I did not found anything meaningful encoded with this type of compression.

Contrary, !0x20 are used a lot for compressing animated parts of buildings and transparent parts of user interface.

OLD:

Code: Select all

Sprite unpacker for Railroad Tycoon II

Extract sprites from YEAREND.IMB
Number of sprites: 8
sprite #00
  sprite type 3
  Use palette PALT0020.PAL
    block #00_00
      image #00_00_00
        image dimensions: 509x597
        ERROR: java.lang.Exception:         unpacking !0x20 not implemented!
...


NEW:

Code: Select all

Sprite unpacker for Railroad Tycoon II, ver. 20220717

Extract sprites from YEAREND.IMB
Number of sprites: 8
sprite #00
  sprite type 3
  Use palette PALT0020.PAL
    block #00_00
      image #00_00_00
        image dimensions: 509x597
        image position: 12,0
        packed size: 242580, unpacked size: 303873
        saved "/home/owner/test/RR2/9/YEAREND.IMB.sprites/00_00_00.unpacked"
...
eldomtom2
Posts: 17
Joined: Sat May 21, 2022 5:07 pm

Re: .imb/.pal files - Railroad Tycoon II

Post by eldomtom2 »

It works perfectly now, thanks a lot for all your hard work!