* stuffextract: output MD5 sums of extracted files (these data are not required now but will be useful in future)

* fixed tools:toHexDump() output of null-bytes.
* added additional check in stuffextract locale detection
This commit is contained in:
False.Genesis 2007-09-30 00:33:21 +00:00
parent 81d50f7c04
commit b166014b4c
4 changed files with 76 additions and 3 deletions

View File

@ -92,8 +92,14 @@ std::string toHexDump(uint8* array,uint32 size,bool spaces)
char buf[5]; char buf[5];
for(uint32 i=0;i<size;i++) for(uint32 i=0;i<size;i++)
{ {
sprintf(buf,(array[i]<0x0F)?"0%X":"%X",(uint32)array[i]); if(array[i])
ss << buf; {
sprintf(buf,(array[i]<0x0F)?"0%X":"%X",(uint32)array[i]);
ss << buf;
}
else
ss << "00"; // little hacklike fix
if(spaces) if(spaces)
ss << ' '; ss << ' ';
} }

View File

@ -10,7 +10,7 @@ char *cconfentry = "SET locale \"";
void SetLocale(char *loc) void SetLocale(char *loc)
{ {
my_locale[4] = 0; my_locale[4] = 0;
if(strlen(loc)) if(loc && strlen(loc))
{ {
memcpy(my_locale,loc,4); memcpy(my_locale,loc,4);
} }

View File

@ -2,6 +2,7 @@
#include <set> #include <set>
#define _COMMON_NO_THREADS #define _COMMON_NO_THREADS
#include "common.h" #include "common.h"
#include "Auth/MD5Hash.h"
#include "tools.h" #include "tools.h"
#include "MPQHelper.h" #include "MPQHelper.h"
#include "dbcfile.h" #include "dbcfile.h"
@ -103,6 +104,32 @@ void OutSCP(char *fn, SCPStorageMap& scp)
} }
} }
void OutMD5(char *path, MD5FileMap& fm)
{
std::string fullname(path);
fullname += "/md5.txt";
printf("Writing MD5 file checksums to '%s'\n",fullname.c_str());
std::fstream fh;
fh.open(fullname.c_str(), std::ios_base::out);
if(fh.is_open())
{
for(MD5FileMap::iterator i = fm.begin(); i != fm.end(); i++)
{
fh << i->first << "|" << toHexDump(i->second,MD5_DIGEST_LENGTH,false) << std::endl; // write file content
delete [] i->second; // and delete previously allocated memory
}
fh.close();
}
else
{
printf("Couldn't output MD5 list to '%s'\n",fullname.c_str());
}
}
bool ConvertDBC(void) bool ConvertDBC(void)
{ {
std::map<uint8,std::string> racemap; // needed to extract other dbc files correctly std::map<uint8,std::string> racemap; // needed to extract other dbc files correctly
@ -296,6 +323,7 @@ void ExtractMaps(void)
char outbuf[2000]; char outbuf[2000];
uint32 extr,extrtotal=0; uint32 extr,extrtotal=0;
MPQHelper mpq("terrain"); MPQHelper mpq("terrain");
MD5FileMap md5map;
CreateDir("stuffextract/data/maps"); CreateDir("stuffextract/data/maps");
for(std::map<uint32,std::string>::iterator it = mapNames.begin(); it != mapNames.end(); it++) for(std::map<uint32,std::string>::iterator it = mapNames.begin(); it != mapNames.end(); it++)
{ {
@ -347,6 +375,12 @@ void ExtractMaps(void)
ADT_FillModelData(bb.contents(),modelNames); ADT_FillModelData(bb.contents(),modelNames);
ADT_FillWMOData(bb.contents(),wmoNames); ADT_FillWMOData(bb.contents(),wmoNames);
depdiff = texNames.size() + modelNames.size() + wmoNames.size() - olddeps; depdiff = texNames.size() + modelNames.size() + wmoNames.size() - olddeps;
MD5Hash h;
h.Update((uint8*)bb.contents(), bb.size());
h.Finalize();
uint8 *md5ptr = new uint8[MD5_DIGEST_LENGTH];
md5map[_PathToFileName(outbuf)] = md5ptr;
memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH);
extr++; extr++;
printf("[%u:%u] %s; %u new deps.\n",extr,it->first,namebuf,depdiff); printf("[%u:%u] %s; %u new deps.\n",extr,it->first,namebuf,depdiff);
} }
@ -358,6 +392,7 @@ void ExtractMaps(void)
} }
printf("\nDONE - %u maps extracted, %u total dependencies.\n",extrtotal, texNames.size() + modelNames.size() + wmoNames.size()); printf("\nDONE - %u maps extracted, %u total dependencies.\n",extrtotal, texNames.size() + modelNames.size() + wmoNames.size());
OutMD5(MAPSDIR,md5map);
} }
void ExtractMapDependencies(void) void ExtractMapDependencies(void)
@ -372,6 +407,7 @@ void ExtractMapDependencies(void)
std::string pathmodel = path + "/model"; std::string pathmodel = path + "/model";
std::string pathwmo = path + "/wmo"; std::string pathwmo = path + "/wmo";
std::string mpqfn,realfn; std::string mpqfn,realfn;
MD5FileMap md5Tex, md5Wmo, md5Model;
CreateDir(pathtex.c_str()); CreateDir(pathtex.c_str());
CreateDir(pathmodel.c_str()); CreateDir(pathmodel.c_str());
CreateDir(pathwmo.c_str()); CreateDir(pathwmo.c_str());
@ -389,6 +425,12 @@ void ExtractMapDependencies(void)
{ {
ByteBuffer& bb = mpqtex.ExtractFile((char*)mpqfn.c_str()); ByteBuffer& bb = mpqtex.ExtractFile((char*)mpqfn.c_str());
fh.write((const char*)bb.contents(),bb.size()); fh.write((const char*)bb.contents(),bb.size());
MD5Hash h;
h.Update((uint8*)bb.contents(), bb.size());
h.Finalize();
uint8 *md5ptr = new uint8[MD5_DIGEST_LENGTH];
md5Tex[_PathToFileName(realfn)] = md5ptr;
memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH);
texdone++; texdone++;
printf("- textures... %u\r",texdone); printf("- textures... %u\r",texdone);
} }
@ -397,6 +439,7 @@ void ExtractMapDependencies(void)
fh.close(); fh.close();
} }
printf("\n"); printf("\n");
OutMD5((char*)pathtex.c_str(),md5Tex);
for(std::set<std::string>::iterator i = modelNames.begin(); i != modelNames.end(); i++) for(std::set<std::string>::iterator i = modelNames.begin(); i != modelNames.end(); i++)
{ {
@ -426,6 +469,12 @@ void ExtractMapDependencies(void)
{ {
ByteBuffer& bb = mpqmodel.ExtractFile((char*)mpqfn.c_str()); ByteBuffer& bb = mpqmodel.ExtractFile((char*)mpqfn.c_str());
fh.write((const char*)bb.contents(),bb.size()); fh.write((const char*)bb.contents(),bb.size());
MD5Hash h;
h.Update((uint8*)bb.contents(), bb.size());
h.Finalize();
uint8 *md5ptr = new uint8[MD5_DIGEST_LENGTH];
md5Model[_PathToFileName(realfn)] = md5ptr;
memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH);
mdone++; mdone++;
printf("- models... %u\r",mdone); printf("- models... %u\r",mdone);
} }
@ -434,6 +483,7 @@ void ExtractMapDependencies(void)
fh.close(); fh.close();
} }
printf("\n"); printf("\n");
OutMD5((char*)pathmodel.c_str(),md5Model);
for(std::set<std::string>::iterator i = wmoNames.begin(); i != wmoNames.end(); i++) for(std::set<std::string>::iterator i = wmoNames.begin(); i != wmoNames.end(); i++)
{ {
@ -447,6 +497,12 @@ void ExtractMapDependencies(void)
{ {
ByteBuffer& bb = mpqwmo.ExtractFile((char*)mpqfn.c_str()); ByteBuffer& bb = mpqwmo.ExtractFile((char*)mpqfn.c_str());
fh.write((const char*)bb.contents(),bb.size()); fh.write((const char*)bb.contents(),bb.size());
MD5Hash h;
h.Update((uint8*)bb.contents(), bb.size());
h.Finalize();
uint8 *md5ptr = new uint8[MD5_DIGEST_LENGTH];
md5Wmo[_PathToFileName(realfn)] = md5ptr;
memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH);
wmosdone++; wmosdone++;
printf("- WMOs... %u\r",wmosdone); printf("- WMOs... %u\r",wmosdone);
} }
@ -455,11 +511,13 @@ void ExtractMapDependencies(void)
fh.close(); fh.close();
} }
printf("\n"); printf("\n");
OutMD5((char*)pathwmo.c_str(),md5Wmo);
} }
void ExtractSoundFiles(void) void ExtractSoundFiles(void)
{ {
MD5FileMap md5data;
uint32 done = 0; uint32 done = 0;
printf("\nExtracting game audio files, %u total...\n",soundFileSet.size()); printf("\nExtracting game audio files, %u total...\n",soundFileSet.size());
CreateDir(SOUNDDIR); CreateDir(SOUNDDIR);
@ -479,6 +537,12 @@ void ExtractSoundFiles(void)
if(bb.size()) if(bb.size())
{ {
fh.write((const char*)bb.contents(),bb.size()); fh.write((const char*)bb.contents(),bb.size());
MD5Hash h;
h.Update((uint8*)bb.contents(), bb.size());
h.Finalize();
uint8 *md5ptr = new uint8[MD5_DIGEST_LENGTH];
md5data[_PathToFileName(*i)] = md5ptr;
memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH);
done++; done++;
printf("- %u files done.\r",done); printf("- %u files done.\r",done);
} }
@ -489,6 +553,7 @@ void ExtractSoundFiles(void)
} }
fh.close(); fh.close();
} }
OutMD5(SOUNDDIR,md5data);
printf("\n"); printf("\n");
} }

View File

@ -12,9 +12,11 @@
#define SOUNDDIR OUTDIR "/data/sound" #define SOUNDDIR OUTDIR "/data/sound"
typedef std::map< uint32,std::list<std::string> > SCPStorageMap; typedef std::map< uint32,std::list<std::string> > SCPStorageMap;
typedef std::map<std::string,uint8*> MD5FileMap;
int main(int argc, char *argv[]); int main(int argc, char *argv[]);
void OutSCP(char*, SCPStorageMap&); void OutSCP(char*, SCPStorageMap&);
void OutMD5(char*, MD5FileMap&);
bool ConvertDBC(void); bool ConvertDBC(void);
void ExtractMaps(void); void ExtractMaps(void);
void ExtractMapDependencies(void); void ExtractMapDependencies(void);