1
Name:
Anonymous
2011-10-25 23:49
int __cdecl sub_5FB5E0(_BYTE *In, int Len, BYTE *Out, _DWORD *OutLen)
{
_BYTE *P; // esi@1
_BYTE *InEnd; // ebp@1
BYTE *O; // eax@1
unsigned int C; // ecx@2
unsigned int U; // ecx@5
_BYTE *NextP; // esi@5
char Done; // dl@8
int v11; // edx@9
unsigned int T; // edx@10
unsigned int L; // ecx@10
_BYTE *B; // edx@18
_BYTE *BB; // edx@18
_BYTE *v16; // eax@19
_BYTE *v17; // edi@24
int UU; // ecx@24
BYTE *v19; // eax@25
_BYTE *v20; // edi@25
char v21; // dl@31
int v22; // edx@32
_BYTE *BBB; // edi@35
char v24; // dl@37
int v25; // edx@38
unsigned int v26; // edx@39
_BYTE *BBBB; // edi@39
int v28; // edx@43
_BYTE *v29; // edi@43
int v30; // ecx@43
int result; // eax@50
int v32; // eax@51
P = In;
*OutLen = 0;
InEnd = &In[Len];
O = Out;
if ( *In > 17u )
{
C = *In - 17;
P = In + 1;
if ( C < 4 )
goto backredCopyLoop;
do
{
*O++ = *P++;
--C;
}
while ( C );
goto backref;
}
aligned:
U = *P;
NextP = P + 1;
if ( U < 0x10 )
{
if ( !U )
{
if ( !*NextP )
{
do
{
Done = NextP[1];
U += 255;
++NextP;
}
while ( !Done );
}
v11 = *NextP++;
U += v11 + 15;
}
T = *(_DWORD *)NextP;
P = NextP + 4;
*(_DWORD *)O = T;
O += 4;
L = U - 1;
if ( L )
{
if ( L < 4 )
{
do
{
*O++ = *P++;
--L;
}
while ( L );
}
else
{
do
{
L -= 4;
*(_DWORD *)O = *(_DWORD *)P;
O += 4;
P += 4;
}
while ( L >= 4 );
for ( ; L; --L )
*O++ = *P++;
}
}
backref:
U = *P;
NextP = P + 1;
if ( U < 0x10 )
{
B = &O[-(U >> 2)] - 4 * *NextP;
P = NextP + 1;
*O++ = *(B - 2049);
BB = B - 2048;
LABEL_19:
*O = *BB;
v16 = O + 1;
*v16 = BB[1];
O = v16 + 1;
goto backrefCopyHead;
}
}
while ( 1 )
{
if ( U >= 0x40 )
{
v17 = &O[-((U >> 2) & 7) - 1] - 8 * *NextP;
P = NextP + 1;
UU = (U >> 5) - 1;
LABEL_25:
*O = *v17;
v19 = O + 1;
*v19 = v17[1];
O = v19 + 1;
v20 = v17 + 2;
do
{
*O++ = *v20++;
--UU;
}
while ( UU );
goto backrefCopyHead;
}
if ( U < 0x20 )
break;
UU = U & 0x1F;
if ( !UU )
{
if ( !*NextP )
{
do
{
v21 = NextP[1];
UU += 255;
++NextP;
}
while ( !v21 );
}
v22 = *NextP++;
UU += v22 + 31;
}
v17 = &O[-((unsigned int)*(_WORD *)NextP >> 2) - 1];
P = NextP + 2;
LABEL_41:
if ( (unsigned int)UU < 6 || (signed int)(O - v17) < 4 )
goto LABEL_25;
v28 = *(_DWORD *)v17;
v29 = v17 + 4;
*(_DWORD *)O = v28;
O += 4;
v30 = UU - 2;
do
{
v30 -= 4;
*(_DWORD *)O = *(_DWORD *)v29;
O += 4;
v29 += 4;
}
while ( (unsigned int)v30 >= 4 );
for ( ; v30; --v30 )
*O++ = *v29++;
backrefCopyHead:
C = *(P - 2) & 3;
if ( !(*(P - 2) & 3) )
goto aligned;
do
{
backredCopyLoop:
*O++ = *P++;
--C;
}
while ( C );
U = *P;
NextP = P + 1;
}
if ( U < 0x10 )
{
BB = &O[-(U >> 2) - 1] - 4 * *NextP;
P = NextP + 1;
goto LABEL_19;
}
BBB = &O[-2048 * (U & 8)];
UU = U & 7;
if ( !UU )
{
if ( !*NextP )
{
do
{
v24 = NextP[1];
UU += 255;
++NextP;
}
while ( !v24 );
}
v25 = *NextP++;
UU += v25 + 7;
}
v26 = *(_WORD *)NextP;
P = NextP + 2;
BBBB = &BBB[-(v26 >> 2)];
if ( BBBB != O )
{
v17 = BBBB - 0x4000;
goto LABEL_41;
}
*OutLen = O - Out;
if ( P == InEnd )
{
result = 0;
}
else
{
v32 = -(P < InEnd);
LOBYTE(v32) = v32 & 0xFC;
result = v32 - 4;
}
return result;
}
2
Name:
VIPPER
2011-10-25 23:55
I can't believe it's not LZO!
also, LZO=JEWS
3
Name:
Anonymous
2011-10-25 23:59
Nevermind. I found original code.
LZO_PUBLIC(int)
DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len,
lzo_byte *out, lzo_uintp out_len,
lzo_voidp wrkmem )
#endif
{
register lzo_byte *op;
register const lzo_byte *ip;
register lzo_uint t;
#if defined(COPY_DICT)
lzo_uint m_off;
const lzo_byte *dict_end;
#else
register const lzo_byte *m_pos;
#endif
const lzo_byte * const ip_end = in + in_len;
#if defined(HAVE_ANY_OP)
lzo_byte * const op_end = out + *out_len;
#endif
#if defined(LZO1Z)
lzo_uint last_m_off = 0;
#endif
LZO_UNUSED(wrkmem);
#if defined(__LZO_QUERY_DECOMPRESS)
if (__LZO_IS_DECOMPRESS_QUERY(in,in_len,out,out_len,wrkmem))
return __LZO_QUERY_DECOMPRESS(in,in_len,out,out_len,wrkmem,0,0);
#endif
#if defined(COPY_DICT)
if (dict)
{
if (dict_len > M4_MAX_OFFSET)
{
dict += dict_len - M4_MAX_OFFSET;
dict_len = M4_MAX_OFFSET;
}
dict_end = dict + dict_len;
}
else
{
dict_len = 0;
dict_end = NULL;
}
#endif
*out_len = 0;
op = out;
ip = in;
if (*ip > 17)
{
t = *ip++ - 17;
if (t < 4)
goto match_next;
assert(t > 0); NEED_OP(t); NEED_IP(t+1);
do *op++ = *ip++; while (--t > 0);
goto first_literal_run;
}
while (TEST_IP && TEST_OP)
{
t = *ip++;
if (t >= 16)
goto match;
if (t == 0)
{
NEED_IP(1);
while (*ip == 0)
{
t += 255;
ip++;
NEED_IP(1);
}
t += 15 + *ip++;
}
assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
#if !defined(LZO_UNALIGNED_OK_4)
if (PTR_ALIGNED2_4(op,ip))
{
#endif
COPY4(op,ip);
op += 4; ip += 4;
if (--t > 0)
{
if (t >= 4)
{
do {
COPY4(op,ip);
op += 4; ip += 4; t -= 4;
} while (t >= 4);
if (t > 0) do *op++ = *ip++; while (--t > 0);
}
else
do *op++ = *ip++; while (--t > 0);
}
#if !defined(LZO_UNALIGNED_OK_4)
}
else
#endif
#endif
#if !defined(LZO_UNALIGNED_OK_4)
{
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
do *op++ = *ip++; while (--t > 0);
}
#endif
first_literal_run:
t = *ip++;
if (t >= 16)
goto match;
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
last_m_off = m_off;
#else
m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
#endif
NEED_OP(3);
t = 3; COPY_DICT(t,m_off)
#else
#if defined(LZO1Z)
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
m_pos = op - t;
last_m_off = t;
#else
m_pos = op - (1 + M2_MAX_OFFSET);
m_pos -= t >> 2;
m_pos -= *ip++ << 2;
#endif
TEST_LOOKBEHIND(m_pos,out); NEED_OP(3);
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
#endif
goto match_done;
while (TEST_IP && TEST_OP)
{
match:
if (t >= 64)
{
#if defined(COPY_DICT)
#if defined(LZO1X)
m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
t = (t >> 5) - 1;
#elif defined(LZO1Y)
m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
t = (t >> 4) - 3;
#elif defined(LZO1Z)
m_off = t & 0x1f;
if (m_off >= 0x1c)
m_off = last_m_off;
else
{
m_off = 1 + (m_off << 6) + (*ip++ >> 2);
last_m_off = m_off;
}
t = (t >> 5) - 1;
#endif
#else
#if defined(LZO1X)
m_pos = op - 1;
m_pos -= (t >> 2) & 7;
m_pos -= *ip++ << 3;
t = (t >> 5) - 1;
#elif defined(LZO1Y)
m_pos = op - 1;
m_pos -= (t >> 2) & 3;
m_pos -= *ip++ << 2;
t = (t >> 4) - 3;
#elif defined(LZO1Z)
{
lzo_uint off = t & 0x1f;
m_pos = op;
if (off >= 0x1c)
{
assert(last_m_off > 0);
m_pos -= last_m_off;
}
else
{
off = 1 + (off << 6) + (*ip++ >> 2);
m_pos -= off;
last_m_off = off;
}
}
t = (t >> 5) - 1;
#endif
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
goto copy_match;
#endif
}
else if (t >= 32)
{
t &= 31;
if (t == 0)
{
NEED_IP(1);
while (*ip == 0)
{
t += 255;
ip++;
NEED_IP(1);
}
t += 31 + *ip++;
}
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
last_m_off = m_off;
#else
m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
#endif
#else
#if defined(LZO1Z)
{
lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
m_pos = op - off;
last_m_off = off;
}
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
m_pos = op - 1;
m_pos -= (* (const lzo_ushortp) ip) >> 2;
#else
m_pos = op - 1;
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
#endif
#endif
ip += 2;
}
else if (t >= 16)
{
#if defined(COPY_DICT)
m_off = (t & 8) << 11;
#else
m_pos = op;
m_pos -= (t & 8) << 11;
#endif
t &= 7;
if (t == 0)
{
NEED_IP(1);
while (*ip == 0)
{
t += 255;
ip++;
NEED_IP(1);
}
t += 7 + *ip++;
}
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off += (ip[0] << 6) + (ip[1] >> 2);
#else
m_off += (ip[0] >> 2) + (ip[1] << 6);
#endif
ip += 2;
if (m_off == 0)
goto eof_found;
m_off += 0x4000;
#if defined(LZO1Z)
last_m_off = m_off;
#endif
#else
#if defined(LZO1Z)
m_pos -= (ip[0] << 6) + (ip[1] >> 2);
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
m_pos -= (* (const lzo_ushortp) ip) >> 2;
#else
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
#endif
ip += 2;
if (m_pos == op)
goto eof_found;
m_pos -= 0x4000;
#if defined(LZO1Z)
last_m_off = op - m_pos;
#endif
#endif
}
else
{
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = 1 + (t << 6) + (*ip++ >> 2);
last_m_off = m_off;
#else
m_off = 1 + (t >> 2) + (*ip++ << 2);
#endif
NEED_OP(2);
t = 2; COPY_DICT(t,m_off)
#else
#if defined(LZO1Z)
t = 1 + (t << 6) + (*ip++ >> 2);
m_pos = op - t;
last_m_off = t;
#else
m_pos = op - 1;
m_pos -= t >> 2;
m_pos -= *ip++ << 2;
#endif
TEST_LOOKBEHIND(m_pos,out); NEED_OP(2);
*op++ = *m_pos++; *op++ = *m_pos;
#endif
goto match_done;
}
#if defined(COPY_DICT)
NEED_OP(t+3-1);
t += 3-1; COPY_DICT(t,m_off)
#else
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
#if !defined(LZO_UNALIGNED_OK_4)
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
{
assert((op - m_pos) >= 4);
#else
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
{
#endif
COPY4(op,m_pos);
op += 4; m_pos += 4; t -= 4 - (3 - 1);
do {
COPY4(op,m_pos);
op += 4; m_pos += 4; t -= 4;
} while (t >= 4);
if (t > 0) do *op++ = *m_pos++; while (--t > 0);
}
else
#endif
{
copy_match:
*op++ = *m_pos++; *op++ = *m_pos++;
do *op++ = *m_pos++; while (--t > 0);
}
#endif
match_done:
#if defined(LZO1Z)
t = ip[-1] & 3;
#else
t = ip[-2] & 3;
#endif
if (t == 0)
break;
match_next:
assert(t > 0); NEED_OP(t); NEED_IP(t+1);
do *op++ = *ip++; while (--t > 0);
t = *ip++;
}
}
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
*out_len = op - out;
return LZO_E_EOF_NOT_FOUND;
#endif
eof_found:
assert(t == 1);
*out_len = op - out;
return (ip == ip_end ? LZO_E_OK :
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
#if defined(HAVE_NEED_IP)
input_overrun:
*out_len = op - out;
return LZO_E_INPUT_OVERRUN;
#endif
#if defined(HAVE_NEED_OP)
output_overrun:
*out_len = op - out;
return LZO_E_OUTPUT_OVERRUN;
#endif
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
lookbehind_overrun:
*out_len = op - out;
return LZO_E_LOOKBEHIND_OVERRUN;
#endif
}
4
Name:
Anonymous
2011-10-26 0:10
Anyway. Compressing 16-bit sprites with LZO is little retarded. But what would you expect from Belgians?
5
Name:
Anonymous
2011-10-26 1:26
>>3
Amazingly enough I find this even harder to read than OP's code, because of all the ifdefs.
6
Name:
Anonymous
2011-10-26 1:38
[quote]lzo_byte[/quote]
Sure is standard-conforming type defintions in here. Why does every single person writing a C library think it would be a good idea to redefine every single fucking type, every single time? Because he can?
7
Name:
Anonymous
2011-10-26 1:39
>>6
[quote]
That was supposed to be
[code] . Guess I should go back to bed now.
8
Name:
Anonymous
2011-10-26 2:03
WTF is the difference between _BYTE and BYTE? I also see a char in there.
9
Name:
Anonymous
2011-10-26 2:13
>>8
Because every single person writing a C library think it would be a good idea to redefine every single fucking type, every single time. Because he can.
10
Name:
Anonymous
2011-10-26 2:15
Eh! And guess what? Sprites are still RLE compressed! Basically they LZ-packed them just for kicks and to increase loading time.
11
Name:
VIPPER
2011-10-26 4:03
Mother of god. What is that?
12
Name:
Anonymous
2011-10-26 7:42
>>11
Looks like output of a popular, but reasonably decent commercial x86 assembly to C decompiler.
13
Name:
Anonymous
2011-10-26 9:59
>>12
It's not decent, cause it doesnt trace usage information or recover structs/VTables.
14
Name:
Anonymous
2011-10-26 10:00
>>13
And it cant detect obvious fastcall routines.
15
Name:
FrozenVoid
2011-10-26 10:03
>>9
The define help to quickly change the format
Suppose you have 10k _BYTE and you need to change them all to INT16, so you just switch 1 define expansion and you're set.
16
Name:
Anonymous
2011-10-26 10:05
>>15
What stops you to do the same with unsigned char?
17
Name:
FrozenVoid
2011-10-26 10:10
>>16
You can have local defines overriding the global defines.
#undef globar_char
#define local_char
local_code
#undef Local_char
#define global_char
18
Name:
Anonymous
2011-10-26 10:20
>>15
Why would you have them as _BYTE in the first place?
19
Name:
FrozenVoid
2011-10-26 10:25
>>18
usually i have this:
#define d #define
d len(mobj) _msize(mobj)
//short type declarations
d u1 unsigned char
d u2 unsigned short
d u4 unsigned int
d u8 unsigned long long
d s1 signed char
d s2 signed short
d s4 signed int
d s8 signed long long
d f2 short float
d f4 float
d f8 double
d f10 long double
//more defines
#undef d
#define local_var_byte u1 <--this can be changed to
local code
#undef loca_var_byte
20
Name:
Anonymous
2011-10-26 10:43
>>13-14
I merely meant that on average it does better than its competitors and allows for some user corrections. Never said it's perfect, just that it's close to the best there is, despite that the current best may be immesely lower quality than we would desire. As for fastcalls routines, you can change the function definitions, same for structures (you can add a structure and change the definition/prototype of some variable or argument or function).
22
Name:
Anonymous
2011-10-26 11:26
The belgians are so retared, they create isometric tiles on fly from square textures. That is why the game loads so "fast".
23
Name:
Anonymous
2011-10-26 11:28
>>23
That's typical of bad amateur programmers. They don't bother with precomputation.
24
Name:
Anonymous
2011-10-26 11:51
>>23
That is typical of C/C++ programmers. They can just dump working state into a level/savegame file. Instead they have to load data every time, user runs program.
25
Name:
FrozenVoid
2011-10-26 11:58
>>23
Obviously you never heard of procedural generation.
26
Name:
Anonymous
2011-10-26 13:51
>>26
That is typical of autists. They can just
cool free ringtones into an anus. Instead they have to hurt their buttfeelings everytime, user becomes a pokemon.