コード例 #1
0
ファイル: System.cpp プロジェクト: Andersoncrh/server
void ExtractDBCFiles(int locale, bool basicLocale)
{
    printf("Extracting dbc files...\n");

    std::set<std::string> dbcfiles;

    // get DBC file list
    for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
    {
        vector<string> files;
        (*i)->GetFileListTo(files);
        for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
            if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
                dbcfiles.insert(*iter);
    }

    std::string path = output_path;
    path += "/dbc/";
    CreateDir(path);
    if (!basicLocale)
    {
        path += langs[locale];
        path += "/";
        CreateDir(path);
    }

    // extract Build info file
    {
        string mpq_name = std::string("component.wow-") + langs[locale] + ".txt";
        string filename = path + mpq_name;

        ExtractFile(mpq_name.c_str(), filename);
    }

    // extract DBCs
    int count = 0;
    for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter)
    {
        string filename = path;
        filename += (iter->c_str() + strlen("DBFilesClient\\"));

        if (ExtractFile(iter->c_str(), filename))
            ++count;
    }
    printf("Extracted %u DBC files\n\n", count);
}
コード例 #2
0
ファイル: mpq_libmpq.cpp プロジェクト: 50059021/wodegongjubao
bool MPQFile::exists(const char* filename)
{
//	if(m_bUseLocalFiles) {
		//wxString fn = gamePath;
		//fn.Append(filename);
		//if (wxFile::Exists(fn.fn_str()))
//		//	return true;
//	}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, filename);
		if (fileno != LIBMPQ_EFILE_NOT_FOUND) 
			return true;
	}

	return false;
}
コード例 #3
0
ファイル: mpq_libmpq.cpp プロジェクト: Aion/caldari
MPQFile::MPQFile(const char* filename):
	eof(false),
	buffer(0),
	pointer(0),
	size(0)
{
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = (*i)->mpq_a;
		
        mpq_hash hash = (*i)->GetHashEntry(filename);
		uint32 blockindex = hash.blockindex;

        if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) {
            continue; //file not found
        }
        
        int fileno = blockindex;

        //int fileno = libmpq_file_number(&mpq_a, filename);
		//if(fileno == LIBMPQ_EFILE_NOT_FOUND)
		//	continue;

        // Found!
		size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
		// HACK: in patch.mpq some files don't want to open and give 1 for filesize
		if (size<=1) {
			eof = true;
			buffer = 0;
			return;
		}
		buffer = new char[size];

		//libmpq_file_getdata
        libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);
		return;

	}
	eof = true;
	buffer = 0;
}
コード例 #4
0
ファイル: mpq_libmpq.cpp プロジェクト: 50059021/wodegongjubao
int MPQFile::getSize(const char* filename)
{
	//if(m_bUseLocalFiles) {
		//wxString fn = gamePath;
		//fn.Append(filename);
		//if (wxFile::Exists(fn.fn_str())) {
		//	wxFile file(fn);
		//	return file.Length();
		//}
	//}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, filename);
		if (fileno != LIBMPQ_EFILE_NOT_FOUND)
			return libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
	}

	return 0;
}
コード例 #5
0
ファイル: vmapexport.cpp プロジェクト: Numielle/server
bool ExtractWmo()
{
    bool success = true;

    for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr)
    {
        vector<string> filelist;

        (*ar_itr)->GetFileListTo(filelist);
        for (vector<string>::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname)
        {
            if (fname->find(".wmo") != string::npos)
                { success = ExtractSingleWmo(*fname); }
        }
    }

    if (success)
        { printf("\nExtract wmo complete (No (fatal) errors)\n"); }

    return success;
}
コード例 #6
0
int MPQFile::getSize(wxString filename)
{
	if( useLocalFiles ) {
		wxString fn1 = wxGetCwd()+SLASH+wxT("Import")+SLASH;
		wxString fn2 = fn1;
		wxString fn3 = gamePath;
		fn1.Append(filename);
		fn2.Append(filename.AfterLast(SLASH));
		fn3.Append(filename);

		wxString fns[] = { fn1, fn2, fn3 };
		for(size_t i=0; i<WXSIZEOF(fns); i++) {
			wxString fn = fns[i];
			if (wxFile::Exists(fn)) {
				wxFile file(fn);
				return file.Length();
			}
		}
	}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		HANDLE &mpq_a = *i->second;
		HANDLE fh;
#ifndef _MINGW
		if( !SFileOpenFileEx( mpq_a, filename.fn_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#else
		if( !SFileOpenFileEx( mpq_a, filename.char_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#endif
			continue;

		DWORD filesize = SFileGetFileSize( fh );
		SFileCloseFile( fh );
		return filesize;
	}

	return 0;
}
コード例 #7
0
ファイル: vmapexport.cpp プロジェクト: armm77/AscEmu
bool ExtractWmo()
{
    bool success = true;

    //const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};

    for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr)
    {
        std::vector<std::string> filelist;

        (*ar_itr)->GetFileListTo(filelist);
        for (std::vector<std::string>::iterator fname = filelist.begin(); fname != filelist.end() && success; ++fname)
        {
            if (fname->find(".wmo") != std::string::npos)
                success = ExtractSingleWmo(*fname);
        }
    }

    if (success)
        printf("\nExtract wmo complete (No (fatal) errors)\n");

    return success;
}
コード例 #8
0
ファイル: vmapexport.cpp プロジェクト: FirstCore/Battle_2.4.3
int ExtractWmo()
{
    char   szLocalFile[1024] = "";
    bool success=true;

    //const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};

    for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr)
    {
        vector<string> filelist;

        (*ar_itr)->GetFileListTo(filelist);
        for (vector<string>::iterator fname=filelist.begin(); fname != filelist.end() && success; ++fname)
        {
            bool file_ok=true;
            if (fname->find(".wmo") != string::npos)
            {
                // Copy files from archive
                //std::cout << "found *.wmo file " << *fname << std::endl;
                sprintf(szLocalFile, "%s/%s", szWorkDirWmo, GetPlainName(fname->c_str()));
                fixnamen(szLocalFile,strlen(szLocalFile));
                FILE * n;
                if ((n = fopen(szLocalFile, "rb"))== NULL)
                {
                    int p = 0;
                    //Select root wmo files
                    const char * rchr = strrchr(GetPlainName(fname->c_str()),0x5f);
                    if (rchr != NULL)
                    {
                        char cpy[4];
                        strncpy((char*)cpy,rchr,4);
                        for (int i=0;i<4; ++i)
                        {
                            int m = cpy[i];
                            if (isdigit(m))
                                p++;
                        }
                    }
                    if (p != 3)
                    {
                        std::cout << "Extracting " << *fname << std::endl;
                        WMORoot * froot = new WMORoot(*fname);
                        if (!froot->open())
                        {
                            printf("Couldn't open RootWmo!!!\n");
                            delete froot;
                            continue;
                        }
                        FILE *output=fopen(szLocalFile,"wb");
                        if (!output)
                        {
                            printf("couldn't open %s for writing!\n", szLocalFile);
                            success=false;
                        }
                        froot->ConvertToVMAPRootWmo(output);
                        int Wmo_nVertices = 0;
                        //printf("root has %d groups\n", froot->nGroups);
                        if (froot->nGroups !=0)
                        {
                            for (uint32 i=0; i<froot->nGroups; ++i)
                            {
                                char temp[1024];
                                strcpy(temp, fname->c_str());
                                temp[fname->length()-4] = 0;
                                char groupFileName[1024];
                                sprintf(groupFileName,"%s_%03d.wmo",temp, i);
                                //printf("Trying to open groupfile %s\n",groupFileName);
                                string s = groupFileName;
                                WMOGroup * fgroup = new WMOGroup(s);
                                if (!fgroup->open())
                                {
                                    printf("Could not open all Group file for: %s\n",GetPlainName(fname->c_str()));
                                    file_ok=false;
                                    break;
                                }

                                Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, froot, preciseVectorData);
                                delete fgroup;
                            }
                        }
                        fseek(output, 8, SEEK_SET); // store the correct no of vertices
                        fwrite(&Wmo_nVertices,sizeof(int),1,output);
                        fclose(output);
                        delete froot;
                    }
                }
                else
                {
                    fclose(n);
                }
            }
            // Delete the extracted file in the case of an error
            if (!file_ok)
                remove(szLocalFile);
        }
    }

    if (success)
        printf("\nExtract wmo complete (No (fatal) errors)\n");

    return success;
}
コード例 #9
0
ファイル: mpq_libmpq.cpp プロジェクト: 50059021/wodegongjubao
MPQFile::MPQFile(const char* filename, bool bUseLocalFiles):
	eof(false),
	buffer(0),
	pointer(0),
	size(0)
{
	m_bUseLocalFiles = bUseLocalFiles;
	if(m_bUseLocalFiles) {

		std::FILE* fp = fopen(filename, "rb");
		if(fp)
		{
			fseek(fp, 0, SEEK_END);
			size = ftell(fp);
			//
			if (size<=1) {
				eof = true;
				buffer = 0;
				return;
			}

			fseek(fp, 0, SEEK_SET);
			buffer = new unsigned char[size];
			fread(buffer,size,1,fp);
			fclose(fp);
			return;
		}

		//String fn;

		//fn = gamePath;
		//fn.Append(filename);

		//if (wxFile::Exists(fn.fn_str())) {
		//	// success
		//	wxFile file;
		//	// if successfully opened
		//	if (file.Open(fn.fn_str(), wxFile::read)) {
		//		size = file.Length();
		//		if (size > 0) {
		//			buffer = new unsigned char[size];
		//			// if successfully read data
		//			if (file.Read(buffer, size) > 0) {
		//				eof = false;
		//				return;
		//			} else {
		//				wxDELETEA(buffer);
		//				eof = true;
		//				size = 0;
		//			}
		//		}
		//	}
		//}
	}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end(); ++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, filename);
		if(fileno == LIBMPQ_EFILE_NOT_FOUND)
			continue;

		// Found!
		size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);

		// HACK: in patch.mpq some files don't want to open and give 1 for filesize
		if (size<=1) {
			eof = true;
			buffer = 0;
			return;
		}

		buffer = new unsigned char[size];
 		libmpq_file_getdata(&mpq_a, fileno, buffer);
		return;
	}

	eof = true;
	buffer = 0;
}
コード例 #10
0
ファイル: mpq_libmpq.cpp プロジェクト: 50059021/wodegongjubao
void getFileLists(std::set<FileTreeItem> &dest, bool filterfunc(std::string))
{
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		int fileno = libmpq_file_number(&mpq_a, "(listfile)");

		if(fileno != LIBMPQ_EFILE_NOT_FOUND) {
			// Found!
			size_t size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno);
			int retVal = libmpq_file_info(&mpq_a, LIBMPQ_FILE_COMPRESSION_TYPE, fileno);

			std::string temp = mpq_a.filename;
			//temp = temp.MakeLower();
			transform(temp.begin(),   temp.end(),   temp.begin(),   tolower);   
			int col = 0;
			if (temp.find("patch.mpq") != std::string::npos)
				col = 1;
			else if (temp.find("patch-2.mpq") != std::string::npos)
				col = 2;

			if (temp.find("wowtest") > -1)
				col = 3;

			// TODO: Add handling for uncompressed files.
			//if () {
			if (size > 0 && retVal != 0) {
				unsigned char *buffer = new unsigned char[size];
				libmpq_file_getdata(&mpq_a, fileno, buffer);
				unsigned char *p = buffer, *end = buffer + size;

				while (p <= end) {
					unsigned char *q=p;
					do {
						if (*q==13) 
							break;
					} while (q++<=end);

					std::string line((char*)p,q-p);
					if (line.length()==0) 
						break;

					//p += line.length();
					p = q + 2;
					//line.erase(line.length()-2, 2); // delete \r\n

					if (filterfunc(line.c_str())) {

						// This is just to help cleanup Duplicates
						// Ideally I should tokenise the string and clean it up automatically
						transform(line.begin(),   line.end(),   line.begin(),   tolower);   
						line[0] -= 32;
						int ret = line.find('\\');
						if (ret>-1)
							line[ret+1] -= 32;

						FileTreeItem tmp;
						tmp.fn = line;
						tmp.col = col;
						dest.insert(tmp);
					}
				}

				S_DEL(buffer);
				p = NULL;
				end = NULL;
			}
		}
	}
}
コード例 #11
0
ファイル: System.cpp プロジェクト: cmangos/mangos-classic
inline void CloseMPQFiles()
{
    for (ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j)(*j)->close();
    gOpenArchives.clear();
}
コード例 #12
0
void getFileLists(std::set<FileTreeItem> &dest, bool filterfunc(wxString))
{
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		HANDLE &mpq_a = *i->second;
		bool isPartial = false;
		if (i->first.AfterLast(SLASH).StartsWith(wxT("wow-update-base")))
			isPartial = false;
		else if (i->first.AfterLast(SLASH).StartsWith(wxT("wow-update-")+langName))
			isPartial = false;
		else if (i->first.AfterLast(SLASH).StartsWith(wxT("wow-update-")))
			isPartial = true;

		HANDLE fh;
		if( SFileOpenFileEx( mpq_a, "(listfile)", 0, &fh ) )
		{
			// Found!
			DWORD filesize = SFileGetFileSize( fh );
			size_t size = filesize;

			wxString temp(i->first);
			temp.MakeLower();
			int col = 0; // Black

			if ((temp.Find(wxT("wow-update-")) > -1) || (temp.Find(wxT("patch.mpq")) > -1))
				col = 1; // Blue
			else if (temp.Find(wxT("cache")) > -1 || temp.Find(wxT("patch-2.mpq")) > -1)
				col = 2; // Red
			else if(temp.Find(wxT("expansion1.mpq")) > -1 || temp.Find(wxT("expansion.mpq")) > -1)
				col = 3; // Outlands Purple
			else if (temp.Find(wxT("expansion2.mpq")) > -1 || temp.Find(wxT("lichking.mpq")) > -1)
				col = 4; // Frozen Blue
			else if (temp.Find(wxT("expansion3.mpq")) > -1)
				col = 5; // Destruction Orange
			else if (temp.Find(wxT("expansion4.mpq")) > -1 || temp.Find(wxT("patch-3.mpq")) > -1)
				col = 6; // Bamboo Green
			else if (temp.Find(wxT("alternate.mpq")) > -1)
				col = 7; // Cyan

			if (size > 0 ) {
				unsigned char *buffer = new unsigned char[size];
				SFileReadFile( fh, buffer, (DWORD)size );
				unsigned char *p = buffer, *end = buffer + size;

				while (p < end) { // if p = end here, no need to go into next loop !
					unsigned char *q=p;
					do {
						if (*q=='\r' || *q=='\n') // carriage return or new line
							break;
					} while (q++<=end);

					wxString line(reinterpret_cast<char *>(p), wxConvUTF8, q-p);
					if (line.Length()==0) 
						break;
					p = q;
					if (*p == '\r')
						p++;
					if (*p == '\n')
						p++;
					//line = line.Trim(); // delete \r\n
					if (isPartial) {
						if (line.Lower().StartsWith(wxT("base\\"))) // strip "base\\"
							line = line.Mid(5);
						else if (line.StartsWith(langName)) // strip "enus\\"
							line = line.Mid(5);
						else
							continue;
					}

					if (filterfunc(wxString(line.mb_str(), wxConvUTF8))) {
						// This is just to help cleanup Duplicates
						// Ideally I should tokenise the string and clean it up automatically
						FileTreeItem tmp;

						tmp.fileName = line;
						line.MakeLower();
						line[0] = toupper(line.GetChar(0));
						int ret = line.Find('\\');
						if (ret>-1)
							line[ret+1] = toupper(line.GetChar(ret+1));

						tmp.displayName = line;
						tmp.color = col;
						dest.insert(tmp);
					}
				}

				wxDELETEA(buffer);
				p = NULL;
				end = NULL;
			}

			SFileCloseFile( fh );
		}
	}
}
コード例 #13
0
MPQArchive::MPQArchive(wxString filename) : ok(false)
{
	wxLogMessage(wxT("Opening %s %s"), filename.Mid(gamePath.Len()).c_str(), isPartialMPQ(filename) ? "(Partial)" : "");
	g_modelViewer->SetStatusText(wxT("Initiating "+filename+wxT(" Archive")));
#ifndef _MINGW
	if (!SFileOpenArchive(filename.fn_str(), 0, MPQ_OPEN_FORCE_MPQ_V1|MPQ_OPEN_READ_ONLY, &mpq_a )) {
#else
	if (!SFileOpenArchive(filename.char_str(), 0, MPQ_OPEN_FORCE_MPQ_V1|MPQ_OPEN_READ_ONLY, &mpq_a )) {
#endif
		int nError = GetLastError();
		wxLogMessage(wxT("Error opening archive %s, error #: 0x%X"), filename.Mid(gamePath.Len()).c_str(), nError);
		return;
	}

	
	// do patch, but skip cache\ directory
	if (!(filename.BeforeLast(SLASH).Lower().Contains(wxT("cache")) && 
		filename.AfterLast(SLASH).Lower().StartsWith(wxT("patch"))) &&
		!isPartialMPQ(filename)) { // skip the PTCH files atrchives
		// do patch
		for(ssize_t j=mpqArchives.GetCount()-1; j>=0; j--) {
			if (!mpqArchives[j].AfterLast(SLASH).StartsWith(wxT("wow-update-")))
				continue;
			if (mpqArchives[j].AfterLast(SLASH).Len() == strlen("wow-update-xxxxx.mpq")) {
#ifndef _MINGW
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].fn_str(), "base", 0);
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].fn_str(), langName.fn_str(), 0);
#else
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].char_str(), "base", 0);
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].char_str(), langName.char_str(), 0);
#endif
				// too many for ptr client, just comment it
				// wxLogMessage(wxT("Appending base & %s patch %s"), langName.c_str(), mpqArchives[j].Mid(gamePath.Len()).c_str());
			} else if (mpqArchives[j].BeforeLast(SLASH) == filename.BeforeLast(SLASH)) { // same directory only
#ifndef _MINGW
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].fn_str(), "", 0);
#else
				SFileOpenPatchArchive(mpq_a, mpqArchives[j].char_str(), "", 0);
#endif
				// wxLogMessage(wxT("Appending patch %s"), mpqArchives[j].Mid(gamePath.Len()).c_str());
			}
		}
	}

	ok = true;
	gOpenArchives.push_back( make_pair( filename, &mpq_a ) );
}

MPQArchive::~MPQArchive()
{
	/*
	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
	{
		mpq_archive &mpq_a = **i;
		
		free(mpq_a.header);
	}
	*/
	//gOpenArchives.erase(gOpenArchives.begin(), gOpenArchives.end());
}

bool MPQArchive::isPartialMPQ(wxString filename)
{
	if (filename.AfterLast(SLASH).StartsWith(wxT("wow-update-")))
		return true;
	return false;
}

void MPQArchive::close()
{
	if (ok == false)
		return;
	SFileCloseArchive(mpq_a);
	for(ArchiveSet::iterator it=gOpenArchives.begin(); it!=gOpenArchives.end();++it)
	{
		HANDLE &mpq_b = *it->second;
		if (&mpq_b == &mpq_a) {
			gOpenArchives.erase(it);
			//delete (*it);
			return;
		}
	}
	
}

bool MPQFile::isPartialMPQ(wxString filename)
{
	if (filename.AfterLast(SLASH).StartsWith(wxT("wow-update-")))
		return true;
	return false;
}

void
MPQFile::openFile(wxString filename)
{
	eof = false;
	buffer = 0;
	pointer = 0;
	size = 0;
	if( useLocalFiles ) {
		wxString fn1 = wxGetCwd()+SLASH+wxT("Import")+SLASH;
		wxString fn2 = fn1;
		wxString fn3 = gamePath;
		fn1.Append(filename);
		fn2.Append(filename.AfterLast(SLASH));
		fn3.Append(filename);

		wxString fns[] = { fn1, fn2, fn3 };
		for(size_t i=0; i<WXSIZEOF(fns); i++) {
			wxString fn = fns[i];
			if (wxFile::Exists(fn)) {
				// success
				wxFile file;
				// if successfully opened
				if (file.Open(fn, wxFile::read)) {
					size = file.Length();
					if (size > 0) {
						buffer = new unsigned char[size];
						// if successfully read data
						if (file.Read(buffer, size) > 0) {
							eof = false;
							file.Close();
							return;
						} else {
							wxDELETEA(buffer);
							eof = true;
							size = 0;
						}
					}
					file.Close();
				}
			}
		}
	}

	// zhCN alternate file mode
	if (bAlternate && !filename.Lower().StartsWith(wxT("alternate"))) {
		wxString alterName = wxT("alternate")+SLASH+filename;

		for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end(); ++i)
		{
			HANDLE &mpq_a = *i->second;

			HANDLE fh;
#ifndef _MINGW
			if( !SFileOpenFileEx( mpq_a, alterName.fn_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#else
			if( !SFileOpenFileEx( mpq_a, alterName.char_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#endif
				continue;

			// Found!
			DWORD filesize = SFileGetFileSize( fh );
			size = filesize;

			// HACK: in patch.mpq some files don't want to open and give 1 for filesize
			if (size<=1) {
				eof = true;
				buffer = 0;
				return;
			}

			buffer = new unsigned char[size];
			SFileReadFile( fh, buffer, (DWORD)size );
			SFileCloseFile( fh );

			return;
		}
	}

	for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end(); ++i)
	{
		HANDLE &mpq_a = *i->second;

		HANDLE fh;
#ifndef _MINGW
		if( !SFileOpenFileEx( mpq_a, filename.fn_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#else
		if( !SFileOpenFileEx( mpq_a, filename.char_str(), SFILE_OPEN_PATCHED_FILE, &fh ) )
#endif
			continue;

		// Found!
		DWORD filesize = SFileGetFileSize( fh );
		size = filesize;

		// HACK: in patch.mpq some files don't want to open and give 1 for filesize
		if (size<=1) {
			eof = true;
			buffer = 0;
			return;
		}

		buffer = new unsigned char[size];
		SFileReadFile( fh, buffer, (DWORD)size );
		SFileCloseFile( fh );

		return;
	}

	eof = true;
	buffer = 0;
}
コード例 #14
0
ファイル: System.cpp プロジェクト: AscNHalf/AscNHalf
int main(int argc, char * arg[])
{
	printf("AscNHalf map extractor for versions 3.2.2 \n");
	printf("============================================================\n\n");

	FILE * tf;
	const char* localeNames[] = { "enUS", "enGB", "deDE", "frFR", "koKR", "zhCN", "zhTW", "esES", "ruRU", 0 };
	int maxPatches = 3;
	int locale = -1;
	char tmp[100];

	tf = fopen("Data/common.MPQ", "r");
	if (!tf)
	{
		printf("Could not find Data/common.MPQ\n");
		return 1;
	}
	fclose(tf);
	new MPQArchive("Data/common.MPQ");

	tf = fopen("Data/common-2.MPQ", "r");
	if (!tf)
	{
		printf("Could not find Data/common-2.MPQ\n");
		return 1;
	}
	fclose(tf);
	new MPQArchive("Data/common-2.MPQ");

	for( size_t i = 0; localeNames[i] != 0; i++ )
	{
		sprintf(tmp, "Data/%s/locale-%s.MPQ", localeNames[i], localeNames[i]);
		tf = fopen(tmp, "r");
		if (!tf)
			continue;
		fclose(tf);
		locale = i;
		new MPQArchive(tmp);
	}

	tf = fopen("Data/expansion.MPQ", "r");
	if (tf)
	{
		fclose(tf);
		new MPQArchive("Data/expansion.MPQ");
		if ( -1 != locale )
		{
			sprintf(tmp, "Data/%s/expansion-locale-%s.MPQ", localeNames[locale], localeNames[locale]);
			new MPQArchive(tmp);
		}
	}

	tf = fopen("Data/lichking.MPQ", "r");
	if (tf)
	{
		fclose(tf);
		new MPQArchive("Data/lichking.MPQ");
		if ( -1 != locale )
		{
			sprintf(tmp, "Data/%s/lichking-locale-%s.MPQ", localeNames[locale], localeNames[locale]);
			new MPQArchive(tmp);
		}
	}

	tf = fopen("Data/patch.MPQ", "r");
	if (tf)
	{
		fclose(tf);
		new MPQArchive("Data/patch.MPQ");
		for(int i = 2; i <= maxPatches; i++)
		{
			sprintf(tmp, "Data/patch-%d.MPQ", i);
			tf = fopen(tmp, "r");
			if (!tf)
				continue;
			fclose(tf);
			new MPQArchive(tmp);
		}
		if ( -1 != locale )
		{
			sprintf(tmp, "Data/%s/patch-%s.MPQ", localeNames[locale], localeNames[locale]);
			tf = fopen(tmp, "r");
			if (tf)
			{
				fclose(tf);
				new MPQArchive(tmp);
				for(int i = 2; i <= maxPatches; i++)
				{
					sprintf(tmp, "Data/%s/patch-%s-%d.MPQ", localeNames[locale], localeNames[locale], i);
					tf = fopen(tmp, "r");
					if (!tf)
						continue;
					fclose(tf);
					new MPQArchive(tmp);
				}
			}
		}
	}

	printf("\nExtracting DBC Files: Identifying files...\n");

	std::set<std::string> dbcFiles;
	int itc = 0;
	for(std::vector<MPQArchive*>::iterator it = gOpenArchives.begin(); it != gOpenArchives.end(); ++it)
	{
		std::vector<std::string> files;
		files = (*it)->GetFileList();
        for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
            if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
                    dbcFiles.insert(*iter);
		SimpleProgressBar(++itc, gOpenArchives.size());
	}
	CleanCache();
	ClearProgressBar();
	printf("Extracting...\n");

    CreateDirectory("DBC", NULL);

    // extract DBCs
    int count = 0;
    for (set<string>::iterator iter = dbcFiles.begin(); iter != dbcFiles.end(); ++iter)
    {
        string filename = "DBC\\";
        filename += (iter->c_str() + strlen("DBFilesClient\\"));

        if(ExtractFile(iter->c_str(), filename))
            ++count;
		SimpleProgressBar(count, dbcFiles.size());
    }
	CleanCache();
	ClearProgressBar();
    printf("Extracted %u DBC files\n\n", count);

	//map.dbc
	DBCFile * dbc = new DBCFile("DBFilesClient\\Map.dbc");
	dbc->open();

	MapCount = dbc->getRecordCount ();
	map_ids = new map_id[MapCount];
	for(unsigned int x = 0; x < MapCount; x++)
	{
		map_ids[x].id = dbc->getRecord (x).getUInt(0);
		strcpy(map_ids[x].name, dbc->getRecord(x).getString(1));
	}
	delete dbc;

	CreateDirectory("maps", NULL);
	ExtractMapsFromMpq();
	delete [] map_ids;

	return 0; // Exit The Program
}
コード例 #15
0
ファイル: loadlib.cpp プロジェクト: AnthoDevMoP/mangos4
ArchiveSetBounds GetArchivesBounds()
{
    return ArchiveSetBounds(gOpenArchives.begin(), gOpenArchives.end());
}
コード例 #16
0
ファイル: loadlib.cpp プロジェクト: AnthoDevMoP/mangos4
void CloseArchives()
{
    for(ArchiveSet::const_iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
        SFileCloseArchive(*i);
    gOpenArchives.clear();
}