Skip to content

Instantly share code, notes, and snippets.

@romhack
Last active April 15, 2018 20:06
Show Gist options
  • Save romhack/fec7321b0670062a1cebbeb5778e2dcf to your computer and use it in GitHub Desktop.
Save romhack/fec7321b0670062a1cebbeb5778e2dcf to your computer and use it in GitHub Desktop.
Winx decompression routine
unsigned int __fastcall decompressGfx(int a1)
{
int v1; // r4@1
int v2; // r0@1
int v3; // r5@1
int v4; // r6@1
int v5; // r2@1
unsigned int result; // r0@1
int v7; // r9@3
int v8; // r0@3
signed int v9; // r1@5
__int16 v10; // r0@5
unsigned int v11; // r10@5
int *outPtr; // r12@5
unsigned int v13; // r9@6
unsigned int v14; // r2@7
int v15; // r3@7
int v16; // r0@8
int v17; // r1@10
unsigned int v18; // r1@16
int v19; // r1@18
int v20; // r3@18
int v21; // t1@18
int v22; // lr@18
int v23; // r1@24
unsigned int v24; // [sp+0h] [bp-68h]@1
unsigned int v25; // [sp+4h] [bp-64h]@2
unsigned int v26; // [sp+Ch] [bp-5Ch]@5
unsigned int v27; // [sp+10h] [bp-58h]@0
unsigned int v28; // [sp+14h] [bp-54h]@2
unsigned int v29; // [sp+18h] [bp-50h]@1
int v30; // [sp+1Ch] [bp-4Ch]@1
int v31; // [sp+20h] [bp-48h]@1
int v32; // [sp+24h] [bp-44h]@1
int v33; // [sp+28h] [bp-40h]@1
int v34; // [sp+2Ch] [bp-3Ch]@1
int v35; // [sp+30h] [bp-38h]@1
int v36; // [sp+34h] [bp-34h]@1
int v37; // [sp+38h] [bp-30h]@1
int v38; // [sp+3Ch] [bp-2Ch]@1
v1 = a1;
v24 = 0;
v2 = *(_BYTE *)(sub_557C4(*(_BYTE *)(a1 + 45)) + 24);
v3 = v2 - 1;
v4 = (v2 - 1) << 8;
v5 = *(_BYTE *)(v1 + 117) << *(_BYTE *)(v2 + 0x30031D8);
v36 = v5 << 8;
v38 = *(_BYTE *)(v1 + 117) << *(_BYTE *)(v2 + 0x30031D8);
v34 = v5 << 16;
v35 = v5 << 12;
v33 = v5 << 20;
v32 = v5 << 24;
v37 = 0x10 * v5;
v31 = v5 << 28;
v29 = 0;
v30 = v5 | 0x10 * v5 | (v5 << 8) | (v5 << 12) | (v5 << 16) | (v5 << 20) | (v5 << 24) | (v5 << 28);
result = *(_BYTE *)(v1 + 110);
if ( *(_BYTE *)(v1 + 110) )
{
do
{
v25 = 0;
v28 = 0;
if ( *(_BYTE *)(v1 + 0x6F) )
{
do
{
v7 = *(_DWORD *)(*(_DWORD *)(v1 + 0x54) + 4 * (v28 + *(_BYTE *)(v1 + 0x6F) * v29));
v8 = *(_DWORD *)(v7 + 0x18);
if ( !v8 )
v8 = *(_DWORD *)(sub_55820(v3003EA0) + 20) + 20 * (**(_DWORD **)(v7 + 16) & 0xFFFF);
v9 = *(_DWORD *)(v8 + 4);
v10 = ((v9 >> 2) & 0x3FC) + 4;
LOWORD(v9) = ((v9 >> 10) & 0x3FC) + 4;
v27 = (unsigned __int8)v9;
v26 = (unsigned __int8)v10;
v11 = 0;
outPtr = (int *)(0x20 * (**(_DWORD **)(v7 + 0x14) >> 21) + 0x6010000);// will unpack to spr buffer
if ( (_BYTE)v9 )
{
do
{
v13 = 0;
if ( v26 )
{
do
{
v14 = 0;
v15 = v25 + *(_WORD *)(v1 + 0x20) * (v24 + v11) + v13 + *(_DWORD *)(v1 + 0x48);
do
{
v16 = *(_DWORD *)(v1 + 0x40);
if ( v16 )
v16 = v30;
v17 = *(_DWORD *)v15;
if ( *(_DWORD *)v15 & v3 )
v16 |= *(_DWORD *)v15 & v3 | v38;
if ( v17 & v4 )
v16 |= v37 | ((v17 & (unsigned int)v4) >> 4);
if ( v17 & (v4 << 8) )
v16 |= v36 | ((v17 & (unsigned int)(v4 << 8)) >> 8);
v18 = v17 & (v4 << 16);
if ( v18 )
v16 |= v35 | (v18 >> 0xC);
v21 = *(_DWORD *)(v15 + 4);
v20 = v15 + 4;
v19 = v21;
v22 = v21 & v3;
if ( v21 & v3 )
v16 |= v34 | (v22 << 16);
if ( v19 & v4 )
v16 |= v33 | ((v19 & v4) << 12);
if ( v19 & (v4 << 8) )
v16 |= v32 | ((v19 & (v4 << 8)) << 8);
v23 = v19 & (v4 << 16);
if ( v23 )
v16 |= v31 | 0x10 * v23;
*outPtr = v16; // save unpacked data to buffer
++outPtr;
v15 = v20 + 4 * ((unsigned int)*(_WORD *)(v1 + 0x20) >> 2) - 4;
v14 = (v14 + 1) & 0xFF;
}
while ( v14 < 8 );
v13 = (unsigned __int8)(v13 + 8);
}
while ( v13 < v26 );
}
v11 = (unsigned __int8)(v11 + 8);
}
while ( v11 < v27 );
}
v25 = (v25 + v26) & 0xFFFEFFFF;
v28 = (unsigned __int8)(v28 + 1);
}
while ( *(_BYTE *)(v1 + 0x6F) > v28 );
}
v24 = (v24 + v27) & 0xFFFEFFFF;
v29 = (unsigned __int8)(v29 + 1);
result = *(_BYTE *)(v1 + 110);
}
while ( result > v29 );
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment