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.

...Iru! (PS1) BIN file decompression for game scripts

Featured Replies

  • Author
  • Localization

BacklogOdyssey, posted Thu Feb 25, 2021 4:23 pm (62482)


Good day everyone!

I'm a hobbyist trying to learn how various game files can be compressed/decompressed in order to get a better understanding of how they work.

The game "...Iru!" is my first project, and unfortunately I'm struggling to wrap my mind around how the game's scripts are compressed and how I can decompress them. As far as I can tell, the game's scripts are stored in various BIN files pertaining to each "area" of the game, and from what research I have been able to do, I've gathered that it's possibly LZSS compression.

That where I'm stuck. Since I'm new to all of this, I'm having difficulty finding any apparent patterns in the file to help me write a script to decompress it and if anyone on here could help me crack the code, that would be greatly appreciated!!

Here is a link to a sample file: https://drive.google.com/file/d/1Uwm-VE ... sp=sharing

Any insight would be more than amazing!!! Thanks again!!

EDIT: I almost forgot! I believe the files are also Shift-JIS encoded.
EDIT 2: Attached sample file to post.
  • Author
  • Localization

aaa801, posted Tue Mar 02, 2021 6:06 pm (62626)


This seems to handle those files, still looking into..

Code:

void sld_decode(int *binData,byte *param_2)

{
  byte bVar1;
  int iVar2;
  byte *pbVar3;
  uint uVar4;
  int iVar5;
  uint uVar6;
  uint uVar7;
  uint *puVar8;
  uint *puVar9;
 
                    /*  != "SL01" */
  if (*binData != 0x31304c53) {
    errorLog("sld_decode");
  }
  puVar8 = (uint *)(binData 3);
  uVar7 = (uint)binData[2] >> 0x18;
  uVar6 = binData[2] & 0xffffff;
  while (uVar6 != 0) {
    uVar6 -= 1;
    iVar5 = 0x20;
    uVar4 = *puVar8;
    puVar9 = puVar8 1;
    do {
      if ((uVar4 & 1) == 0) {
        iVar2 = (*(byte *)((int)puVar9 1) & 0xf) 2;
        puVar8 = (uint *)((int)puVar9 2);
        if (iVar2 == 2) {
          bVar1 = *(byte *)puVar8;
          puVar8 = (uint *)((int)puVar9 3);
          iVar2 = bVar1 0x12;
        }
        pbVar3 = param_2 (-1 - ((uint)*(byte *)puVar9 | (*(byte *)((int)puVar9 1) & 0xf0) <<4))
        ;
        do {
          bVar1 = *pbVar3;
          pbVar3 = pbVar3 1;
          iVar2 = -1;
          *param_2 = bVar1;
          param_2 = param_2 1;
        } while (iVar2 != 0);
      }
      else {
        puVar8 = (uint *)((int)puVar9 1);
        *param_2 = *(byte *)puVar9;
        param_2 = param_2 1;
      }
      iVar5 = -1;
      uVar4 >>= 1;
      puVar9 = puVar8;
    } while (iVar5 != 0);
  }
  if (uVar7 != 0) {
    uVar6 = *puVar8;
    puVar8 = puVar8 1;
    do {
      if ((uVar6 & 1) == 0) {
        iVar5 = (*(byte *)((int)puVar8 1) & 0xf) 2;
        puVar9 = (uint *)((int)puVar8 2);
        if (iVar5 == 2) {
          bVar1 = *(byte *)puVar9;
          puVar9 = (uint *)((int)puVar8 3);
          iVar5 = bVar1 0x12;
        }
        pbVar3 = param_2 (-1 - ((uint)*(byte *)puVar8 | (*(byte *)((int)puVar8 1) & 0xf0) <<4))
        ;
        do {
          bVar1 = *pbVar3;
          pbVar3 = pbVar3 1;
          iVar5 = -1;
          *param_2 = bVar1;
          param_2 = param_2 1;
        } while (iVar5 != 0);
      }
      else {
        puVar9 = (uint *)((int)puVar8 1);
        *param_2 = *(byte *)puVar8;
        param_2 = param_2 1;
      }
      uVar7 -= 1;
      uVar6 >>= 1;
      puVar8 = puVar9;
    } while (uVar7 != 0);
  }
  return;
}



  • Author
  • Localization

BacklogOdyssey, posted Wed Mar 03, 2021 3:04 pm (62641)


Wow!! I truly appreciate the help. I'll try to tinker with this as well to see if I can figure anything out. The code example will definitely help me understand how these files work. Just let me know if you'd like me to attach any other files.

Also, just to be sure I'm not going down the wrong path, which language is this? C , C, quickBMS?
  • Author
  • Localization

aaa801, posted Wed Mar 03, 2021 7:04 pm (62644)


BacklogOdyssey wrote:
Wow!! I truly appreciate the help. I'll try to tinker with this as well to see if I can figure anything out. The code example will definitely help me understand how these files work. Just let me know if you'd like me to attach any other files.

Also, just to be sure I'm not going down the wrong path, which language is this? C , C, quickBMS?


The worst language, decompiled c :D


Note this only handles the ones that are compressed, I haven't found where the actual data processing is done yet, but the smallest files should be already decompressed (without sl01 magic)
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.