Format pak.h. Update to the latest data manager.

This commit is contained in:
lzwdgc 2016-06-01 00:45:03 +03:00
parent 26588ebbfd
commit 540af823f4
4 changed files with 271 additions and 275 deletions

View file

@ -154,7 +154,7 @@ void write_mmo(std::string db, const storage &s)
} }
else else
{ {
bld_ids[o] = iter->getId(); bld_ids[o] = iter->second->getId();
} }
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
@ -178,11 +178,11 @@ void write_mmo(std::string db, const storage &s)
mb.scale = ASSIGN(object->m_rotate_z[2].z, 1); mb.scale = ASSIGN(object->m_rotate_z[2].z, 1);
auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const auto &p) auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const auto &p)
{ {
return *p.second.get() == mb; return *p.second == mb;
}); });
if (i == storage->mapBuildings.end()) if (i == storage->mapBuildings.end())
{ {
auto mb2 = storage->addMapBuilding(storage->maps[map_id].get()); auto mb2 = storage->addMapBuilding(storage->maps[map_id]);
mb.setId(mb2->getId()); mb.setId(mb2->getId());
*mb2 = mb; *mb2 = mb;
inserted++; inserted++;
@ -216,7 +216,7 @@ void write_mmo(std::string db, const storage &s)
bld_ids[o] = bld->getId(); bld_ids[o] = bld->getId();
} }
else else
bld_ids[o] = iter->getId(); bld_ids[o] = iter->second->getId();
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
{ {
@ -239,11 +239,11 @@ void write_mmo(std::string db, const storage &s)
mb.scale = ASSIGN(object->m_rotate_z[2].z, 1); mb.scale = ASSIGN(object->m_rotate_z[2].z, 1);
auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const auto &p) auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const auto &p)
{ {
return *p.second.get() == mb; return *p.second == mb;
}); });
if (i == storage->mapObjects.end()) if (i == storage->mapObjects.end())
{ {
auto mb2 = storage->addMapObject(storage->maps[map_id].get()); auto mb2 = storage->addMapObject(storage->maps[map_id]);
mb.setId(mb2->getId()); mb.setId(mb2->getId());
*mb2 = mb; *mb2 = mb;
inserted++; inserted++;

View file

@ -1,312 +1,309 @@
#pragma once #pragma once
#define _BYTE uint8_t #define _BYTE uint8_t
#define _WORD uint16_t #define _WORD uint16_t
#define _DWORD uint32_t #define _DWORD uint32_t
#define LOBYTE(x) (*((_BYTE*)&(x))) #define LOBYTE(x) (*((_BYTE *)&(x)))
#define LOWORD(x) (*((_WORD*)&(x))) #define LOWORD(x) (*((_WORD *)&(x)))
#define HIBYTE(x) (*((_BYTE*)&(x)+1)) #define HIBYTE(x) (*((_BYTE *)&(x) + 1))
#define BYTEn(x, n) (*((_BYTE*)&(x)+n)) #define BYTEn(x, n) (*((_BYTE *)&(x) + n))
#define BYTE1(x) BYTEn(x, 1) #define BYTE1(x) BYTEn(x, 1)
template<class T> int8_t __SETS__(T x) template <class T>
int8_t __SETS__(T x)
{ {
if ( sizeof(T) == 1 ) if (sizeof(T) == 1)
return int8_t(x) < 0; return int8_t(x) < 0;
if ( sizeof(T) == 2 ) if (sizeof(T) == 2)
return int16_t(x) < 0; return int16_t(x) < 0;
if ( sizeof(T) == 4 ) if (sizeof(T) == 4)
return int32_t(x) < 0; return int32_t(x) < 0;
return int64_t(x) < 0; return int64_t(x) < 0;
} }
template<class T, class U> int8_t __OFSUB__(T x, U y) template <class T, class U>
int8_t __OFSUB__(T x, U y)
{ {
if ( sizeof(T) < sizeof(U) ) if (sizeof(T) < sizeof(U))
{ {
U x2 = x; U x2 = x;
int8_t sx = __SETS__(x2); int8_t sx = __SETS__(x2);
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y)); return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2 - y));
} }
else else
{ {
T y2 = y; T y2 = y;
int8_t sx = __SETS__(x); int8_t sx = __SETS__(x);
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2)); return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x - y2));
} }
} }
inline void memset32(void *ptr, uint32_t value, int count) inline void memset32(void *ptr, uint32_t value, int count)
{ {
uint32_t *p = (uint32_t *)ptr; uint32_t *p = (uint32_t *)ptr;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
*p++ = value; *p++ = value;
} }
char *decode_f1(char *input, int size, char *output) char *decode_f1(char *input, int size, char *output)
{ {
char *result; // eax@1 char *result; // eax@1
char *v4; // ebx@1 char *v4; // ebx@1
int v5; // ebp@1 int v5; // ebp@1
char *v6; // edi@2 char *v6; // edi@2
char *v7; // edx@4 char *v7; // edx@4
int v8; // ecx@6 int v8; // ecx@6
int v9; // esi@6 int v9; // esi@6
int v10; // esi@6 int v10; // esi@6
int v11; // ecx@6 int v11; // ecx@6
char *v12; // edx@7 char *v12; // edx@7
int v13; // esi@7 int v13; // esi@7
result = input; result = input;
v4 = &input[size]; v4 = &input[size];
v5 = 8; v5 = 8;
if ( input < &input[size] ) if (input < &input[size])
{
v6 = output;
do
{ {
if ( v5 == 8 ) v6 = output;
{ do
v7 = (char *)(uint8_t)*result++;
v5 = 0;
input = v7;
if ( result == v4 )
break;
}
if ( (uint8_t)input & 1 )
{
v8 = (uint8_t)*result;
v9 = (uint8_t)result[1];
result += 2;
v10 = ((v8 & 0xF) << 8) + v9;
v11 = (v8 >> 4) + 4;
if ( v11 )
{ {
v12 = &v6[-v10]; if (v5 == 8)
v13 = v11; {
do v7 = (char *)(uint8_t)*result++;
{ v5 = 0;
*v6++ = *v12++; input = v7;
--v13; if (result == v4)
} break;
while ( v13 ); }
} if ((uint8_t)input & 1)
} {
else v8 = (uint8_t)*result;
{ v9 = (uint8_t)result[1];
*v6++ = *result++; result += 2;
} v10 = ((v8 & 0xF) << 8) + v9;
++v5; v11 = (v8 >> 4) + 4;
input = (char *)((signed int)input >> 1); if (v11)
{
v12 = &v6[-v10];
v13 = v11;
do
{
*v6++ = *v12++;
--v13;
} while (v13);
}
}
else
{
*v6++ = *result++;
}
++v5;
input = (char *)((signed int)input >> 1);
} while (result < v4);
} }
while ( result < v4 ); return result;
}
return result;
} }
char decode_f2(char *input, int size, char *output) char decode_f2(char *input, int size, char *output)
{ {
int c; // eax@1 int c; // eax@1
char v4; // bl@1 char v4; // bl@1
char *v5; // edx@1 char *v5; // edx@1
char *v6; // esi@2 char *v6; // esi@2
char *v7; // edx@4 char *v7; // edx@4
int c_1; // edi@4 int c_1; // edi@4
int c_2; // edi@7 int c_2; // edi@7
char *v10; // ecx@8 char *v10; // ecx@8
int c_3; // edi@8 int c_3; // edi@8
LOBYTE(c) = size; LOBYTE(c) = size;
v4 = *input; v4 = *input;
v5 = input + 1; v5 = input + 1;
if ( input + 1 < &input[size] ) if (input + 1 < &input[size])
{
v6 = output;
do
{ {
LOBYTE(c) = *v5; v6 = output;
if ( *v5 == v4 ) do
{
c = (uint8_t)v5[1];
v7 = v5 + 1;
c_1 = (uint8_t)v7[1];
v5 = v7 + 2;
if ( c != 255 || c_1 != 255 )
{ {
c_2 = ((c & 0xF) << 8) + c_1; LOBYTE(c) = *v5;
c = (c >> 4) + 4; if (*v5 == v4)
if ( c )
{
v10 = &v6[-c_2];
c_3 = c;
do
{ {
LOBYTE(c) = *v10; c = (uint8_t)v5[1];
*v6++ = *v10++; v7 = v5 + 1;
--c_3; c_1 = (uint8_t)v7[1];
v5 = v7 + 2;
if (c != 255 || c_1 != 255)
{
c_2 = ((c & 0xF) << 8) + c_1;
c = (c >> 4) + 4;
if (c)
{
v10 = &v6[-c_2];
c_3 = c;
do
{
LOBYTE(c) = *v10;
*v6++ = *v10++;
--c_3;
} while (c_3);
}
}
else
{
*v6++ = v4;
}
} }
while ( c_3 ); else
} {
} *v6++ = c;
else ++v5;
{ }
*v6++ = v4; } while (v5 < &input[size]);
}
}
else
{
*v6++ = c;
++v5;
}
} }
while ( v5 < &input[size] ); return c;
}
return c;
} }
int decode_f3(char *input, int size, char *output) int decode_f3(char *input, int size, char *output)
{ {
uint16_t s; // cx@1 uint16_t s; // cx@1
char *v4; // edi@1 char *v4; // edi@1
int result; // eax@1 int result; // eax@1
int idx; // edx@1 int idx; // edx@1
bool v7; // zf@1 bool v7; // zf@1
bool v8; // sf@1 bool v8; // sf@1
uint8_t v9; // of@1 uint8_t v9; // of@1
int v10; // ebp@1 int v10; // ebp@1
char *v11; // ebx@2 char *v11; // ebx@2
uint16_t v12; // ax@3 uint16_t v12; // ax@3
uint8_t v13; // cl@4 uint8_t v13; // cl@4
__int16 v14; // ax@6 __int16 v14; // ax@6
unsigned int v15; // esi@6 unsigned int v15; // esi@6
void *v16; // edi@7 void *v16; // edi@7
int v17; // ebp@7 int v17; // ebp@7
int v18; // eax@7 int v18; // eax@7
int v19; // edi@7 int v19; // edi@7
int i; // ecx@7 int i; // ecx@7
int v21; // [sp+8h] [bp-4h]@1 int v21; // [sp+8h] [bp-4h]@1
int v22; // [sp+14h] [bp+8h]@1 int v22; // [sp+14h] [bp+8h]@1
LOBYTE(s) = 0; LOBYTE(s) = 0;
v4 = input; v4 = input;
HIBYTE(s) = *input; HIBYTE(s) = *input;
result = size >> 1; result = size >> 1;
idx = 1; idx = 1;
v9 = __OFSUB__(size >> 1, 1); v9 = __OFSUB__(size >> 1, 1);
v7 = size >> 1 == 1; v7 = size >> 1 == 1;
v8 = (size >> 1) - 1 < 0; v8 = (size >> 1) - 1 < 0;
v22 = size >> 1; v22 = size >> 1;
v10 = s; v10 = s;
v21 = s; v21 = s;
if ( !((uint8_t)(v8 ^ v9) | v7) ) if (!((uint8_t)(v8 ^ v9) | v7))
{
v11 = output;
do
{ {
v12 = *(_WORD *)&v4[2 * idx]; v11 = output;
if ( (*(_WORD *)&v4[2 * idx] & 0xFF00) == (_WORD)v10 ) do
{
v13 = *(_WORD *)&v4[2 * idx++];
if ( v12 != (uint16_t)v10 + 255 )
{ {
v14 = *(_WORD *)&v4[2 * idx]; v12 = *(_WORD *)&v4[2 * idx];
v15 = v13 + 3; if ((*(_WORD *)&v4[2 * idx] & 0xFF00) == (_WORD)v10)
if ( (signed int)v15 > 0 )
{
LOWORD(v10) = *(_WORD *)&v4[2 * idx];
v16 = v11;
v11 += 2 * v15;
v17 = v10 << 16;
LOWORD(v17) = v14;
v18 = v17;
v10 = v21;
memset32(v16, v18, v15 >> 1);
v19 = (int)((char *)v16 + 4 * (v15 >> 1));
for ( i = (v13 + 3) & 1; i; --i )
{ {
*(_WORD *)v19 = v18; v13 = *(_WORD *)&v4[2 * idx++];
v19 += 2; if (v12 != (uint16_t)v10 + 255)
{
v14 = *(_WORD *)&v4[2 * idx];
v15 = v13 + 3;
if ((signed int)v15 > 0)
{
LOWORD(v10) = *(_WORD *)&v4[2 * idx];
v16 = v11;
v11 += 2 * v15;
v17 = v10 << 16;
LOWORD(v17) = v14;
v18 = v17;
v10 = v21;
memset32(v16, v18, v15 >> 1);
v19 = (int)((char *)v16 + 4 * (v15 >> 1));
for (i = (v13 + 3) & 1; i; --i)
{
*(_WORD *)v19 = v18;
v19 += 2;
}
v4 = input;
}
goto LABEL_13;
}
*(_WORD *)v11 = *(_WORD *)&v4[2 * idx];
} }
v4 = input; else
} {
goto LABEL_13; *(_WORD *)v11 = v12;
} }
*(_WORD *)v11 = *(_WORD *)&v4[2 * idx]; v11 += 2;
} LABEL_13:
else result = v22;
{ ++idx;
*(_WORD *)v11 = v12; } while (idx < v22);
}
v11 += 2;
LABEL_13:
result = v22;
++idx;
} }
while ( idx < v22 ); return result;
}
return result;
} }
int decode_f4(char *input, int size, char *output, int segment_offset) int decode_f4(char *input, int size, char *output, int segment_offset)
{ {
char *in3; // edx@1 char *in3; // edx@1
int result; // eax@1 int result; // eax@1
char in1; // bl@1 char in1; // bl@1
int ptr; // esi@1 int ptr; // esi@1
char *out1; // edi@2 char *out1; // edi@2
char c; // al@3 char c; // al@3
char c_next; // cl@4 char c_next; // cl@4
char v11; // al@6 char v11; // al@6
unsigned int c_prev; // ebp@6 unsigned int c_prev; // ebp@6
int v13; // eax@7 int v13; // eax@7
char in2; // [sp+1h] [bp-1h]@1 char in2; // [sp+1h] [bp-1h]@1
in3 = input; in3 = input;
result = size; result = size;
in1 = *input; in1 = *input;
ptr = 1; ptr = 1;
in2 = *input; in2 = *input;
if ( size > 1 ) if (size > 1)
{
out1 = output;
while ( 1 )
{ {
c = in3[ptr]; out1 = output;
if ( c != in1 ) while (1)
break; {
c_next = in3[ptr++ + 1]; c = in3[ptr];
if ( c_next == -1 ) if (c != in1)
{ break;
*out1 = in1; c_next = in3[ptr++ + 1];
LABEL_9: if (c_next == -1)
++out1; {
goto LABEL_10; *out1 = in1;
} LABEL_9:
v11 = in3[ptr++ + 1]; ++out1;
c_prev = (uint8_t)c_next + 3; goto LABEL_10;
if ( (signed int)c_prev > 0 ) }
{ v11 = in3[ptr++ + 1];
LOBYTE(segment_offset) = v11; c_prev = (uint8_t)c_next + 3;
BYTE1(segment_offset) = v11; if ((signed int)c_prev > 0)
v13 = segment_offset << 16; {
LOWORD(v13) = segment_offset; LOBYTE(segment_offset) = v11;
in1 = in2; BYTE1(segment_offset) = v11;
memset32(out1, v13, c_prev >> 2); v13 = segment_offset << 16;
in3 = input; LOWORD(v13) = segment_offset;
memset(&out1[4 * (c_prev >> 2)], v13, c_prev & 3); in1 = in2;
out1 = &output[c_prev]; memset32(out1, v13, c_prev >> 2);
LABEL_10: in3 = input;
output = out1; memset(&out1[4 * (c_prev >> 2)], v13, c_prev & 3);
} out1 = &output[c_prev];
result = size; LABEL_10:
++ptr; output = out1;
if ( ptr >= size ) }
return result; result = size;
++ptr;
if (ptr >= size)
return result;
}
*out1 = c;
goto LABEL_9;
} }
*out1 = c; return result;
goto LABEL_9;
}
return result;
} }

View file

@ -27,15 +27,14 @@ void unpak(string fn)
return; return;
pak p; pak p;
p.load(f); p.load(f);
auto read_write_any_file = [&](record &file) for (auto &f : p.files)
{ {
record &file = f.second;
cout << "Unpacking " << file.name << "\n"; cout << "Unpacking " << file.name << "\n";
vector<char> buf(file.len); vector<char> buf(file.len);
file.read(&p, &buf[0], file.len); file.read(&p, &buf[0], file.len);
file.write(fn + ".dir", buf); file.write(fn + ".dir", buf);
}; };
for (auto &f : p.files)
read_write_any_file(f.second);
fclose(f); fclose(f);
} }