Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include "Main.h"
  2. #include "PakFile_v1.h"
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. Statistics mpakDump_v1(FILE* f, const std::string& name)
  9. {
  10.     u32 i;
  11.     MPakHeader h;
  12.     Statistics out;
  13.     fseek(f, 0, SEEK_SET);
  14.  
  15.     fread(&h, sizeof(h), 1, f);
  16.     toWORD(h.version1);
  17.     toWORD(h.version2);
  18.     toDWORD(h.size);
  19.  
  20.     assert(h.version1 == 3);
  21.     assert(h.version2 == 5);
  22.     assert(h.size     == 0);
  23.  
  24.     //read name entry header
  25.     EntryHeader neh;
  26.     fread(&neh, sizeof(neh), 1, f);
  27.     toDWORD(neh.entryCount);
  28.  
  29.     cout << hex;
  30.     vector<NameEntry> ne;
  31.     ne.resize(neh.entryCount);
  32.     vector<string> names;
  33.     names.resize(neh.entryCount);
  34.     //output name entries
  35.     if (bVerbose)
  36.         cout << string(70, '-') << endl
  37.         << neh.entryCount << " name entries: " << endl;
  38.     for (i = 0; i < neh.entryCount; ++i)
  39.     {
  40.         fread(&ne[i], sizeof(NameEntry), 1, f);
  41.         toDWORD(ne[i].id);
  42.         toDWORD(ne[i].nameLength);
  43.  
  44.         char name[1000] = {0};
  45.         fread(name, 1, ne[i].nameLength, f);
  46.         names[i] = name;
  47.         if (bVerbose)
  48.         {
  49.             cout << string(ne[i].tag, 4) << " " << ne[i].id << " "
  50.             << string(name, ne[i].nameLength) << endl;
  51.         }
  52.     }
  53.  
  54.     //read entry header
  55.     EntryHeader eh;
  56.     fread(&eh, sizeof(eh), 1, f);
  57.     toDWORD(eh.entryCount);
  58.  
  59.     //output entries
  60.     if (bVerbose)
  61.     {
  62.         cout << string(70, '-') << endl
  63.         << eh.entryCount << " entries: " << endl;
  64.     }
  65.     int count = 0;
  66.     for (i = 0; i < eh.entryCount; ++i)
  67.     {
  68.         string fname = string("");
  69.         Entry e;
  70.         fread(&e, sizeof(e), 1, f);
  71.         toDWORD(e.isCompressed);
  72.  
  73.         toDWORD(e.id);
  74.         for (u32 ii = 0; ii < neh.entryCount; ii++)
  75.         {
  76.             if (e.id == ne[ii].id)
  77.             {
  78.                 fname = names[ii].c_str();
  79.                 break;
  80.             }
  81.         }
  82.         toDWORD(e.length);
  83.         toDWORD(e.offset);
  84.  
  85.         assert(e.isCompressed == 0 || e.isCompressed == 1);
  86.         count += e.isCompressed;
  87.  
  88.         //dump file
  89.         std::ostringstream nameStream;
  90.         nameStream << name << hex << "\\" << e.isCompressed << "_"  << e.id << "."
  91.             << string(e.tag, 4);
  92.  
  93.         if (!bQuiet)
  94.         {
  95.             if (bVerbose)
  96.                 cout << fixed << hex << "\rCurrent File " << e.id << "." << string(e.tag, 4);
  97.             else
  98.                 cout << "\rFile " << dec <<  fixed << (i+1) << " of " << eh.entryCount << " " << setprecision(2)<< ((float)((i+1)*100)/eh.entryCount) << "% Complete";
  99.         }
  100.         dumpFile(nameStream.str(), f, e.offset, e.length);
  101.     }
  102.     cout << dec << endl;
  103.     out.numFiles = eh.entryCount;
  104.     out.numNames = neh.entryCount;
  105.     out.numCompressed = count;
  106.     return out;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement