Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

.imb/.pal files - Railroad Tycoon II

Featured Replies

  • Author
  • Localization

eldomtom2, posted Sat May 21, 2022 5:10 pm (71628)


I want to rip the sprites from Railroad Tycoon II. I've extracted the data .pak, and the sprites appear to be in .imb and .pal files. Does anyone know anything about viewing/converting these?

Extracted .pak: https://mega.nz/file/164EGLDb#6TB8nqyeq ... LPvMSvP8Kc
  • Author
  • Localization

eldomtom2, posted Mon Jun 06, 2022 10:12 pm (71882)


In case it helps anyone, here are some examples of the apparent headers for the files:
Quote:
29 00 00 00 03 00 00 00 CE 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 84 80 B5 82 01 00 00 00 01 00 00 00 01 00 2A 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 5F 00 00 00 63 00 00 00 DC 80 B5 82 B3 1B 00 00 0C

Quote:
01 00 00 00 03 00 00 00 F6 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 93 9C 82 01 00 00 00 01 00 00 00 01 00 2A 00 00 00 00 03 00 00 00 18 00 00 00 08 00 00 00 F0 00 00 00 03 01 00 00 38 F0 1B 83 0D D0 00 00 29

Quote:
08 00 00 00 03 00 00 00 BF 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 30 14 BF 82 02 00 00 00 01 00 00 00 01 00 2A 00 00 00 00 03 00 00 00 F9 FF FF FF EE FF FF FF 0E 00 00 00 16 00 00 00 A4 14 BF 82 35 01 00 00 04
  • Author
  • Localization

Bwolna, posted Fri Jun 10, 2022 3:25 pm (71935)


Quote:
29 00 00 00 03 00 00 00 CE 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 84 80 B5 82 01 00 00 00 01 00 00 00 01 00 2A 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 5F 00 00 00 63 00 00 00 DC 80 B5 82 B3 1B 00 00 0C


My guesses:

00 00 00 29 - number of sprites in this file

next bytes you provided are the header for first sprite
...
00 00 00 5F - something like width of sprite (not exactly)
00 00 00 63 - something like height of sprite (not exactly)
...
00 00 1B B3 - size of sprite body (starting from last byte of provided header).

(if any)

As for "not exactly" part - for Credits.IMB dimencions in header are 400h * 300h, while real data are 40Ch * 300h.
Image is divided by 7 one-pixel vertical lines and has 2 two-pixel vertical lines on the borders. But it's still Bh out of extra 0?h. Size of blocks between vertical lines is 80h, so it may be somehow connected to the value of the last header byte (84h for Credits).
  • Author
  • Localization

eldomtom2, posted Fri Jun 10, 2022 8:18 pm (71940)


Bwolna wrote:
As for "not exactly" part - for Credits.IMB dimencions in header are 400h * 300h, while real data are 40Ch * 300h.

How do you know the size of the real data?
  • Author
  • Localization

Bwolna, posted Fri Jun 10, 2022 10:11 pm (71946)


Size of real data is provided in header.
"Real" dimensions could be found for some non-compressed sprites in programs for visualization of raw data. I used GBS:



Image
  • Author
  • Localization

eldomtom2, posted Fri Jun 10, 2022 10:22 pm (71947)


Er, how did you extract sprites from CREDITS.IMB?
  • Author
  • Localization

Bwolna, posted Sat Jun 11, 2022 9:40 am (71957)


Using any program that allows to copy parts of the binary file. Many hex-editors can do this, but I used dd utility:

Code:
dd if=CREDITS.IMB bs=1 skip=$((0x70)) count=$((0xC2401)) of=00.sprite

Code:
dd if=WINLOSE.IMB bs=1 skip=$((0x70)) count=$((0x451A9)) of=00.sprite


Instructions: https://stackoverflow.com/questions/142 ... hin-a-file
  • Author
  • Localization

eldomtom2, posted Sat Jun 11, 2022 12:52 pm (71965)


That isn't any good if I don't know how to identify the actual sprite data.
  • Author
  • Localization

Bwolna, posted Sat Jun 11, 2022 7:49 pm (71970)


Sprites are compressed. Simple cases like CREDITS can be decompressed with something like this:

Code:
         int position = 0;
         int destPos = 0;
         boolean finish = false;
         while (!finish) {
            int lineStartPos = destPos;
            int firstByte = readByte(source, position );
            if ((firstByte & 0x80) > 0) position ;
            boolean lineFinished = false;
            while (!lineFinished && !finish) {
               int controlByte = readByte(source, position );
               if ((controlByte & 0x80) > 0) {
                  if ((controlByte & 0x40) > 0) {
                     int skipSize = controlByte & 0x3F;
                     if (skipSize == 0) {
                        finish = true;
                     } else {
                        destPos = skipSize;
                     }
                  } else if ((controlByte & 0x20) == 0) {
                     // !TODO
                  } else {
                     // !TODO
                  }
               } else if (controlByte == 0) {
                  destPos = lineStartPos width;
                  lineFinished = true;
               } else {
                  for (int i=0; i               }
            }
         }
  • Author
  • Localization

eldomtom2, posted Sat Jun 11, 2022 10:06 pm (71971)


That doesn't help me identify the sprite data. If I can identify the precise values that contain the actual images, then I can easily extract them without the aid of scripts.
  • Author
  • Localization

Bwolna, posted Sun Jun 12, 2022 2:34 am (71974)


Sorry, I don't understand what do you mean.
Size of compressed sprite and dimension of decompressed sprite are written in headers.
  • Author
  • Localization

eldomtom2, posted Sun Jun 12, 2022 3:55 pm (71999)


I have several questions:

How "compressed" are the sprites? If I deleted everything but the image data, would I have an image or would I have to do something else?

What do you mean by "simple cases like CREDITS"? Is this just about the number of images contained in each files, or is there something more going on?
  • Author
  • Localization

Bwolna, posted Sun Jun 12, 2022 7:33 pm (72007)


eldomtom2 wrote:
How "compressed" are the sprites?

Some sort of Run-length_encoding algorithm was used to compress "empty" (transparent?) parts of images.

eldomtom2 wrote:
If I deleted everything but the image data, would I have an image or would I have to do something else?


If by "everything but the image data" you mean only headers, the answer will be "no". But if you'll delete headers, delete control sequences of commands (inserted to compressed sprite by original compressor) and insert missed transparent blocks then you will get the uncompressed image data.

eldomtom2 wrote:
What do you mean by "simple cases like CREDITS"? Is this just about the number of images contained in each files, or is there something more going on?


No, not the number of images in one file. Simple cases are cases where original image did not contain transparent pixels. Like CREDITS and some other rectangular pictures.

For such images compressor still added some control sequences of command, but did not remove anything. So this files could be viewed in Texture Finder or GBS (that I personally use) even in "compressed form". In those tools control sequences of commands will look like vertical lines (look at my screenshot in previous post).

P.S. I didn't completely understand the algorithm of compression so far, so it could be that some sprites are compressed with some other tricks in addition to RLE.

P.P.S. first sprite from file BL1SHEEP.IMB. Compressed size = 11999 bytes. Decompressed size = 20736. After decompression:

Image
  • Author
  • Localization

eldomtom2, posted Mon Jun 13, 2022 3:00 pm (72027)


BL1SHEEP.IMB seems to contain transparent pixels from that image and what I know of how it's used in the game, so did you work out how to decompress images that contain transparent pixels?
  • Author
  • Localization

Bwolna, posted Mon Jun 13, 2022 3:36 pm (72028)


Bwolna wrote:
can be decompressed with something like this:

Code:
         int position = 0;
         int destPos = 0;
         boolean finish = false;
         while (!finish) {
            int lineStartPos = destPos;
            int firstByte = readByte(source, position );
            if ((firstByte & 0x80) > 0) position ;
            boolean lineFinished = false;
            while (!lineFinished && !finish) {
               int controlByte = readByte(source, position );
               if ((controlByte & 0x80) > 0) {
                  if ((controlByte & 0x40) > 0) {
                     int skipSize = controlByte & 0x3F;
                     if (skipSize == 0) {
                        finish = true;
                     } else {
                        destPos = skipSize;
                     }
                  } else if ((controlByte & 0x20) == 0) {
                     // !TODO
                  } else {
                     // !TODO
                  }
               } else if (controlByte == 0) {
                  destPos = lineStartPos width;
                  lineFinished = true;
               } else {
                  for (int i=0; i               }
            }
         }
  • Author
  • Localization

eldomtom2, posted Sat Jun 18, 2022 5:21 pm (72151)


Huh, but didn't you say that was only for simple cases?
  • Author
  • Localization

Bwolna, posted Sat Jun 18, 2022 8:02 pm (72152)


Yes, I did. But later tests showed that more complex cases (like BL1SHEEP and BL2CMINE) could be de decompressed by this code. There are still TODO left, that would be (probably) needed for some of the images.
  • Author
  • Localization

eldomtom2, posted Mon Jun 20, 2022 9:08 pm (72197)


Great, I suppose my main question then is how would I run that code?
  • Author
  • Localization

Bwolna, posted Wed Jun 22, 2022 5:13 pm (72241)


That code snippet is a part of small java program (quick and dirty).
But you can treat it as a Pseudocode and write your own decompressor with any language you know the best.
  • Author
  • Localization

eldomtom2, posted Wed Jun 22, 2022 5:22 pm (72242)


Would it be possible for you to share the actual program?
  • Author
  • Localization

Bwolna, posted Sat Jun 25, 2022 10:50 pm (72297)


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:
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"

rr2spr.zip

  • Author
  • Localization

eldomtom2, posted Sun Jun 26, 2022 11:31 am (72303)


Thanks, I can extract the files fine using that, but how do I get GBS to open the extracted files?
  • Author
  • Localization

Bwolna, posted Sun Jun 26, 2022 12:23 pm (72307)


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

Code:
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.
  • Author
  • Localization

eldomtom2, posted Sun Jun 26, 2022 12:41 pm (72308)


Great, I take it you haven't figured out how the palettes work yet?
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.