Skip to content

Commit

Permalink
Add tool for PAK file decompression.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Jan 20, 2011
1 parent 00a68b3 commit 335f4bf
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 77 deletions.
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ include_directories(
set(CMAKE_CXX_COMPILER /usr/bin/wineg++)
set(CMAKE_C_COMPILER /usr/bin/winegcc)


#set temporally less gcc problems
set(CMAKE_CXX_FLAGS "-fpermissive -w -m32")

Expand All @@ -36,3 +35,22 @@ target_link_libraries(arx dsound dxguid gdi32 shell32 dinput comdlg32 ole32 comc
add_custom_target(remake
COMMAND make clean && rm CMakeCache.txt && cmake . -G\"Unix Makefiles\" && make -j`getconf _NPROCESSORS_ONLN`
)



# compile unpak tool

set(UNPAK_SRC_DIR tools/unpak)

include_directories(
include
)

# normal build TODO
#set(CMAKE_CXX_COMPILER g++)
#set(CMAKE_C_COMPILER gcc)
#set(CMAKE_CXX_FLAGS "-fpermissive -w")

add_executable(unpak tools/unpak/unpak.cpp src/hermes/PakEntry.cpp src/hermes/PakReader.cpp src/hermes/HashMap.cpp src/hermes/blast.cpp)

# target_link_libraries(unpak z)
31 changes: 18 additions & 13 deletions src/hermes/HashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@ ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
#include <cstdlib>
#include <cstring>

#include <algorithm>
using std::transform;

#include <string>
using std::string;

using std::size_t;

//-----------------------------------------------------------------------------
HashMap::HashMap(size_t _iSize)
{
tTab = (Entry *)malloc(_iSize * sizeof(Entry));
iNbCollisions = iNbNoInsert = 0;

iSize = _iSize;
iFill = 0;

while (_iSize--)
{
tTab[_iSize].lpszName = NULL;

for(size_t i = 0; i < _iSize; i++) {
tTab[i].lpszName = NULL;
}

iMask = iSize - 1;
}

Expand All @@ -65,8 +70,8 @@ HashMap::~HashMap()
bool HashMap::AddString(const char * _lpszText, void * _pMem)
{
// todo string;
const char * lpszTextLow = _lpszText;
// char * lpszTextLow = strlwr(_lpszText);
string lpszTextLow = _lpszText;
transform(lpszTextLow.begin(), lpszTextLow.end(), lpszTextLow.begin(), tolower);

if (iFill >= iSize * 0.75)
{
Expand All @@ -76,7 +81,7 @@ bool HashMap::AddString(const char * _lpszText, void * _pMem)
tTab = (Entry *)realloc(tTab, iSize * sizeof(Entry));
}

int iKey = GetKey(lpszTextLow);
int iKey = GetKey(lpszTextLow.c_str());
int iH1 = FuncH1(iKey);
int iH2 = FuncH2(iKey);

Expand All @@ -88,7 +93,7 @@ bool HashMap::AddString(const char * _lpszText, void * _pMem)

if (!tTab[iH1].lpszName)
{
tTab[iH1].lpszName = strdup(lpszTextLow);
tTab[iH1].lpszName = strdup(lpszTextLow.c_str());
tTab[iH1].pMem = _pMem;
iFill++;
return true;
Expand All @@ -109,10 +114,10 @@ bool HashMap::AddString(const char * _lpszText, void * _pMem)
void * HashMap::GetPtrWithString(const char * _lpszText)
{
// todo string;
const char * lpszTextLow = _lpszText;
string lpszTextLow = _lpszText;
// char * lpszTextLow = _strlwr(_lpszText);

int iKey = GetKey(lpszTextLow);
int iKey = GetKey(lpszTextLow.c_str());
int iH1 = FuncH1(iKey);
int iH2 = FuncH2(iKey);

Expand All @@ -124,7 +129,7 @@ void * HashMap::GetPtrWithString(const char * _lpszText)

if (tTab[iH1].lpszName)
{
if (!strcmp(lpszTextLow, tTab[iH1].lpszName))
if (!strcmp(lpszTextLow.c_str(), tTab[iH1].lpszName))
{
return tTab[iH1].pMem;
}
Expand Down
18 changes: 13 additions & 5 deletions src/hermes/PakEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PakDirectory::PakDirectory(PakDirectory * p, const char * n)

if (n)
{
unsigned int l;
size_t l;
this->name = GetFirstDir(n, &l);

if (this->name)
Expand Down Expand Up @@ -134,7 +134,8 @@ PakDirectory::~PakDirectory()
//#############################################################################
PakDirectory * PakDirectory::AddSousRepertoire(const char * sname)
{
unsigned int nbs = this->nbsousreps, l;
unsigned int nbs = this->nbsousreps;
size_t l;
PakDirectory * rf = this->fils;

const char * fdir = GetFirstDir(sname, &l);
Expand Down Expand Up @@ -165,7 +166,8 @@ PakDirectory * PakDirectory::AddSousRepertoire(const char * sname)
//#############################################################################
bool PakDirectory::DelSousRepertoire(const char * sname)
{
unsigned int nbs = this->nbsousreps, l;
unsigned int nbs = this->nbsousreps;
size_t l;
PakDirectory * rf = this->fils;

const char * fdir = GetFirstDir(sname, &l);
Expand Down Expand Up @@ -218,16 +220,21 @@ bool PakDirectory::DelSousRepertoire(const char * sname)
delete[] fdir;
return false;
}

#include <stdio.h>

//#############################################################################
PakDirectory * PakDirectory::GetSousRepertoire(const char * sname)
{
unsigned int nbs = this->nbsousreps, l;
unsigned int nbs = this->nbsousreps;
size_t l;
PakDirectory * rf = this->fils;

const char * fdir = GetFirstDir(sname, &l);

while (nbs--)
{

if (!strcasecmp(fdir, rf->name))
{
delete[] fdir;
Expand Down Expand Up @@ -357,6 +364,7 @@ static char * GetFirstDir(const char * dir, size_t * l)

strncpy(fdir, dir, *l);
fdir[*l] = 0;
fdir[*l - 1] = '\\'; // TODO use "/" seperator

return fdir;
}
Expand Down
22 changes: 11 additions & 11 deletions src/hermes/PakManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ long _PAK_DirectoryExist(char * name)
char temp[256];
strcpy(temp, name + g_pak_workdir_len);
long l = leng - g_pak_workdir_len ;
if (temp[l] != '\\') strcat(temp, "\\");
if (temp[l] != '\\' && temp[l] != '/') strcat(temp, "\\");

vector<PakDirectory *> pvRepertoire(pPakManager->ExistDirectory(temp));

Expand Down Expand Up @@ -691,8 +691,8 @@ bool PakManager::Read(char * _lpszName, void * _pMem)
{
vector<PakReader *>::iterator i;

if ((_lpszName[0] == '\\') /*||
(_lpszName[0] == '/')*/)
if ((_lpszName[0] == '\\') ||
(_lpszName[0] == '/'))
{
_lpszName++;
}
Expand All @@ -717,8 +717,8 @@ void * PakManager::ReadAlloc(char * _lpszName, int * _piTaille)
{
vector<PakReader *>::iterator i;

if ((_lpszName[0] == '\\') /*||
(_lpszName[0] == '/')*/)
if ((_lpszName[0] == '\\') ||
(_lpszName[0] == '/'))
{
_lpszName++;
}
Expand All @@ -744,8 +744,8 @@ int PakManager::GetSize(char * _lpszName)
{
vector<PakReader *>::iterator i;

if ((_lpszName[0] == '\\') /*||
(_lpszName[0] == '/')*/)
if ((_lpszName[0] == '\\') ||
(_lpszName[0] == '/'))
{
_lpszName++;
}
Expand All @@ -771,8 +771,8 @@ PakFileHandle * PakManager::fOpen(char * _lpszName)
{
vector<PakReader *>::iterator i;

if ((_lpszName[0] == '\\') /*||
(_lpszName[0] == '/')*/)
if ((_lpszName[0] == '\\') ||
(_lpszName[0] == '/'))
{
_lpszName++;
}
Expand Down Expand Up @@ -893,8 +893,8 @@ bool PakManager::ExistFile(char * _lpszName)
{
vector<PakReader *>::iterator i;

if ((_lpszName[0] == '\\') /*||
(_lpszName[0] == '/')*/)
if ((_lpszName[0] == '\\') ||
(_lpszName[0] == '/'))
{
_lpszName++;
}
Expand Down
Loading

0 comments on commit 335f4bf

Please sign in to comment.