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

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
BacklogOdyssey
Posts: 2
Joined: Thu Feb 25, 2021 4:22 pm

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

Post by BacklogOdyssey »

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.
aaa801
Posts: 48
Joined: Wed Oct 12, 2016 12:22 pm

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

Post by aaa801 »

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

Code: Select all


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;
}



BacklogOdyssey
Posts: 2
Joined: Thu Feb 25, 2021 4:22 pm

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

Post by BacklogOdyssey »

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?
aaa801
Posts: 48
Joined: Wed Oct 12, 2016 12:22 pm

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

Post by aaa801 »

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)