Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Main.h"
- #include "PakFile_v1.h"
- #include <windows.h>
- using namespace std;
- Statistics mpakDump_v1(FILE* f, const std::string& name)
- {
- u32 i;
- MPakHeader h;
- Statistics out;
- fseek(f, 0, SEEK_SET);
- fread(&h, sizeof(h), 1, f);
- toWORD(h.version1);
- toWORD(h.version2);
- toDWORD(h.size);
- assert(h.version1 == 3);
- assert(h.version2 == 5);
- assert(h.size == 0);
- //read name entry header
- EntryHeader neh;
- fread(&neh, sizeof(neh), 1, f);
- toDWORD(neh.entryCount);
- cout << hex;
- vector<NameEntry> ne;
- ne.resize(neh.entryCount);
- vector<string> names;
- names.resize(neh.entryCount);
- //output name entries
- if (bVerbose)
- cout << string(70, '-') << endl
- << neh.entryCount << " name entries: " << endl;
- for (i = 0; i < neh.entryCount; ++i)
- {
- fread(&ne[i], sizeof(NameEntry), 1, f);
- toDWORD(ne[i].id);
- toDWORD(ne[i].nameLength);
- char name[1000] = {0};
- fread(name, 1, ne[i].nameLength, f);
- names[i] = name;
- if (bVerbose)
- {
- cout << string(ne[i].tag, 4) << " " << ne[i].id << " "
- << string(name, ne[i].nameLength) << endl;
- }
- }
- //read entry header
- EntryHeader eh;
- fread(&eh, sizeof(eh), 1, f);
- toDWORD(eh.entryCount);
- //output entries
- if (bVerbose)
- {
- cout << string(70, '-') << endl
- << eh.entryCount << " entries: " << endl;
- }
- int count = 0;
- for (i = 0; i < eh.entryCount; ++i)
- {
- string fname = string("");
- Entry e;
- fread(&e, sizeof(e), 1, f);
- toDWORD(e.isCompressed);
- toDWORD(e.id);
- for (u32 ii = 0; ii < neh.entryCount; ii++)
- {
- if (e.id == ne[ii].id)
- {
- fname = names[ii].c_str();
- break;
- }
- }
- toDWORD(e.length);
- toDWORD(e.offset);
- assert(e.isCompressed == 0 || e.isCompressed == 1);
- count += e.isCompressed;
- //dump file
- std::ostringstream nameStream;
- nameStream << name << hex << "\\" << e.isCompressed << "_" << e.id << "."
- << string(e.tag, 4);
- if (!bQuiet)
- {
- if (bVerbose)
- cout << fixed << hex << "\rCurrent File " << e.id << "." << string(e.tag, 4);
- else
- cout << "\rFile " << dec << fixed << (i+1) << " of " << eh.entryCount << " " << setprecision(2)<< ((float)((i+1)*100)/eh.entryCount) << "% Complete";
- }
- dumpFile(nameStream.str(), f, e.offset, e.length);
- }
- cout << dec << endl;
- out.numFiles = eh.entryCount;
- out.numNames = neh.entryCount;
- out.numCompressed = count;
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement